@Override
    public ProcResult fetchResult() throws AnalysisException {
        Preconditions.checkNotNull(globalStateMgr);
        BaseProcResult result = new BaseProcResult();
        result.setNames(TITLE_NAMES);

        List<String> dbNames = globalStateMgr.getLocalMetastore().listDbNames();
        if (dbNames == null || dbNames.isEmpty()) {
            // empty
            return result;
        }

        // get info
        List<List<Comparable>> dbInfos = new ArrayList<List<Comparable>>();
        for (String dbName : dbNames) {
            Database db = globalStateMgr.getDb(dbName);
            if (db == null) {
                continue;
            }
            List<Comparable> dbInfo = new ArrayList<Comparable>();
            Locker locker = new Locker();
            locker.lockDatabase(db, LockType.READ);
            try {
                int tableNum = db.getTables().size();
                dbInfo.add(db.getId());
                dbInfo.add(dbName);
                dbInfo.add(tableNum);

                long dataQuota = db.getDataQuota();
                Pair<Double, String> quotaUnitPair = DebugUtil.getByteUint(dataQuota);
                String readableQuota = DebugUtil.DECIMAL_FORMAT_SCALE_3.format(quotaUnitPair.first) + " "
                        + quotaUnitPair.second;
                dbInfo.add(readableQuota);

                dbInfo.add(TimeUtils.longToTimeString(db.getLastCheckTime()));

                long replicaQuota = db.getReplicaQuota();
                dbInfo.add(replicaQuota);

            } finally {
                locker.unLockDatabase(db, LockType.READ);
            }
            dbInfos.add(dbInfo);
        }

        // order by dbId, asc
        ListComparator<List<Comparable>> comparator = new ListComparator<List<Comparable>>(0);
        Collections.sort(dbInfos, comparator);

        // set result
        for (List<Comparable> info : dbInfos) {
            List<String> row = new ArrayList<String>(info.size());
            for (Comparable comparable : info) {
                row.add(comparable.toString());
            }
            result.addRow(row);
        }
        return result;
    }
@Test
    public void testFetchResultNormal() throws AnalysisException {
        new Expectations(globalStateMgr) {
            {
                globalStateMgr.getLocalMetastore().listDbNames();
                minTimes = 0;
                result = Lists.newArrayList("db1", "db2");

                globalStateMgr.getDb("db1");
                minTimes = 0;
                result = db1;

                globalStateMgr.getDb("db2");
                minTimes = 0;
                result = db2;

                globalStateMgr.getDb("db3");
                minTimes = 0;
                result = null;

                globalStateMgr.getDb(db1.getId());
                minTimes = 0;
                result = db1;

                globalStateMgr.getDb(db2.getId());
                minTimes = 0;
                result = db2;

                globalStateMgr.getDb(anyLong);
                minTimes = 0;
                result = null;
            }
        };

        DbsProcDir dir;
        ProcResult result;

        dir = new DbsProcDir(globalStateMgr);
        result = dir.fetchResult();
        Assert.assertNotNull(result);
        Assert.assertTrue(result instanceof BaseProcResult);

        Assert.assertEquals(
                Lists.newArrayList("DbId", "DbName", "TableNum", "Quota", "LastConsistencyCheckTime", "ReplicaQuota"),
                result.getColumnNames());
        List<List<String>> rows = Lists.newArrayList();
        rows.add(Arrays.asList(String.valueOf(db1.getId()), db1.getOriginName(), "0", "8388608.000 TB",
                FeConstants.NULL_STRING, "9223372036854775807"));
        rows.add(Arrays.asList(String.valueOf(db2.getId()), db2.getOriginName(), "0", "8388608.000 TB",
                FeConstants.NULL_STRING, "9223372036854775807"));
        Assert.assertEquals(rows, result.getRows());
    }