src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
---|---|
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public boolean updateCachedFiles(Long fid, Long lastAccessTime, Integer numAccessed) throws MetaStoreException { try { return cacheFileDao.update(fid, lastAccessTime, numAccessed) >= 0; } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testUpdateCachedFiles() throws Exception { metaStore.insertCachedFiles(80L, "testPath", 1000L, 2000L, 100); metaStore.insertCachedFiles(90L, "testPath2", 2000L, 3000L, 200); Map<String, Long> pathToId = new HashMap<>(); pathToId.put("testPath", 80L); pathToId.put("testPath2", 90L); pathToId.put("testPath3", 100L); List<FileAccessEvent> events = new ArrayList<>(); events.add(new FileAccessEvent("testPath", 3000L)); events.add(new FileAccessEvent("testPath", 4000L)); events.add(new FileAccessEvent("testPath2", 4000L)); events.add(new FileAccessEvent("testPath2", 5000L)); events.add(new FileAccessEvent("testPath3", 8000L)); events.add(new FileAccessEvent("testPath3", 9000L)); metaStore.updateCachedFiles(pathToId, events); List<CachedFileStatus> statuses = metaStore.getCachedFileStatus(); Assert.assertTrue(statuses.size() == 2); Map<Long, CachedFileStatus> statusMap = new HashMap<>(); for (CachedFileStatus status : statuses) { statusMap.put(status.getFid(), status); } Assert.assertTrue(statusMap.containsKey(80L)); CachedFileStatus first = statusMap.get(80L); Assert.assertTrue(first.getLastAccessTime() == 4000L); Assert.assertTrue(first.getNumAccessed() == 102); Assert.assertTrue(statusMap.containsKey(90L)); CachedFileStatus second = statusMap.get(90L); Assert.assertTrue(second.getLastAccessTime() == 5000L); Assert.assertTrue(second.getNumAccessed() == 202); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public List<CachedFileStatus> getCachedFileStatus() throws MetaStoreException { try { return cacheFileDao.getAll(); } catch (EmptyResultDataAccessException e) { return new ArrayList<>(); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testGetCachedFileStatus() throws Exception { metaStore.insertCachedFiles(6L, "testPath", 1490918400000L, 234567L, 456); metaStore.insertCachedFiles(19L, "testPath", 1490918400000L, 234567L, 456); metaStore.insertCachedFiles(23L, "testPath", 1490918400000L, 234567L, 456); CachedFileStatus cachedFileStatus = metaStore.getCachedFileStatus(6); Assert.assertTrue(cachedFileStatus.getFromTime() == 1490918400000L); List<CachedFileStatus> cachedFileList = metaStore.getCachedFileStatus(); List<Long> fids = metaStore.getCachedFids(); Assert.assertTrue(fids.size() == 3); Assert.assertTrue(cachedFileList.get(0).getFid() == 6); Assert.assertTrue(cachedFileList.get(1).getFid() == 19); Assert.assertTrue(cachedFileList.get(2).getFid() == 23); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public int deleteFinishedCmdletsWithGenTimeBefore(long timestamp) throws MetaStoreException { try { return cmdletDao.deleteBeforeTime(timestamp); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testdeleteFinishedCmdletsWithGenTimeBefore() throws Exception { Map<String, String> args = new HashMap(); CmdletInfo command1 = new CmdletInfo(0, 78, CmdletState.CANCELLED, "test", 123L, 232444444L); metaStore.insertCmdlet(command1); CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.DONE, "tt", 128L, 232444994L); metaStore.insertCmdlet(command2); ActionInfo actionInfo = new ActionInfo(1, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo); ActionInfo actionInfo2 = new ActionInfo(2, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo2); ActionInfo actionInfo3 = new ActionInfo(3, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo3); metaStore.deleteFinishedCmdletsWithGenTimeBefore(125); Assert.assertTrue(metaStore.getCmdletById(0) == null); Assert.assertTrue(metaStore.getActionById(1) == null); Assert.assertTrue(metaStore.getActionById(2) != null); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public int deleteKeepNewCmdlets(long num) throws MetaStoreException { try { return cmdletDao.deleteKeepNewCmd(num); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testdeleteKeepNewCmdlets() throws Exception { Map<String, String> args = new HashMap(); CmdletInfo command1 = new CmdletInfo(0, 78, CmdletState.CANCELLED, "test", 123L, 232444444L); metaStore.insertCmdlet(command1); CmdletInfo command2 = new CmdletInfo(1, 78, CmdletState.DONE, "tt", 128L, 232444994L); metaStore.insertCmdlet(command2); ActionInfo actionInfo = new ActionInfo(1, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo); ActionInfo actionInfo2 = new ActionInfo(2, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo2); ActionInfo actionInfo3 = new ActionInfo(3, 0, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo3); metaStore.deleteKeepNewCmdlets(1); Assert.assertTrue(metaStore.getCmdletById(0) == null); Assert.assertTrue(metaStore.getActionById(1) == null); Assert.assertTrue(metaStore.getActionById(2) != null); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public List<ActionInfo> getNewCreatedActions( int size) throws MetaStoreException { if (size < 0) { return new ArrayList<>(); } try { return actionDao.getLatestActions(size); } catch (EmptyResultDataAccessException e) { return new ArrayList<>(); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testGetNewCreatedActions() throws Exception { Map<String, String> args = new HashMap(); List<ActionInfo> actionInfos; ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertAction(actionInfo); actionInfo.setActionId(2); metaStore.insertAction(actionInfo); actionInfos = metaStore.getNewCreatedActions(1); Assert.assertTrue(actionInfos.size() == 1); actionInfos = metaStore.getNewCreatedActions("cache", 1, true, true); Assert.assertTrue(actionInfos.size() == 1); actionInfos = metaStore.getNewCreatedActions(2); Assert.assertTrue(actionInfos.size() == 2); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public long getMaxActionId() throws MetaStoreException { try { return actionDao.getMaxId(); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testGetMaxActionId() throws Exception { long currentId = metaStore.getMaxActionId(); Map<String, String> args = new HashMap(); Assert.assertTrue(currentId == 0); ActionInfo actionInfo = new ActionInfo( currentId, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertActions(new ActionInfo[] {actionInfo}); currentId = metaStore.getMaxActionId(); Assert.assertTrue(currentId == 1); actionInfo = new ActionInfo( currentId, 1, "cache", args, "Test", "Test", true, 123213213L, true, 123123L, 100); metaStore.insertActions(new ActionInfo[] {actionInfo}); currentId = metaStore.getMaxActionId(); Assert.assertTrue(currentId == 2); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void setClusterConfig( ClusterConfig clusterConfig) throws MetaStoreException { try { if (clusterConfigDao.getCountByName(clusterConfig.getNodeName()) == 0) { clusterConfigDao.insert(clusterConfig); } else { clusterConfigDao.updateByNodeName(clusterConfig.getNodeName(), clusterConfig.getConfigPath()); } } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testSetClusterConfig() throws MetaStoreException { ClusterConfig clusterConfig = new ClusterConfig(1, "test", "test1"); metaStore.setClusterConfig(clusterConfig); List<ClusterConfig> list = new LinkedList<>(); list.add(clusterConfig); Assert.assertTrue(metaStore.listClusterConfig().equals(list)); list.get(0).setConfig_path("test2"); metaStore.setClusterConfig(list.get(0)); Assert.assertTrue(metaStore.listClusterConfig().equals(list)); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void delClusterConfig( ClusterConfig clusterConfig) throws MetaStoreException { try { if (clusterConfigDao.getCountByName(clusterConfig.getNodeName()) > 0) { clusterConfigDao.delete(clusterConfig.getCid()); } } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testDelClusterConfig() throws MetaStoreException { ClusterConfig clusterConfig = new ClusterConfig(1, "test", "test1"); metaStore.setClusterConfig(clusterConfig); metaStore.delClusterConfig(clusterConfig); Assert.assertTrue(metaStore.listClusterConfig().size() == 0); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void setGlobalConfig( GlobalConfig globalConfig) throws MetaStoreException { try { if (globalConfigDao.getCountByName(globalConfig.getPropertyName()) > 0) { globalConfigDao.update(globalConfig.getPropertyName(), globalConfig.getPropertyValue()); } else { globalConfigDao.insert(globalConfig); } } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testSetGlobalConfig() throws MetaStoreException { GlobalConfig globalConfig = new GlobalConfig(1, "test", "test1"); metaStore.setGlobalConfig(globalConfig); Assert.assertTrue(metaStore.getDefaultGlobalConfigByName("test").equals(globalConfig)); globalConfig.setPropertyValue("test2"); metaStore.setGlobalConfig(globalConfig); Assert.assertTrue(metaStore.getDefaultGlobalConfigByName("test").equals(globalConfig)); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void insertDataNodeInfo(DataNodeInfo dataNodeInfo) throws MetaStoreException { try { dataNodeInfoDao.insert(dataNodeInfo); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testInsertDataNodeInfo() throws Exception { DataNodeInfo insertInfo1 = new DataNodeInfo("UUID1", "hostname", "www.ssm.com", 100, 50, "lab"); metaStore.insertDataNodeInfo(insertInfo1); List<DataNodeInfo> getInfo1 = metaStore.getDataNodeInfoByUuid("UUID1"); Assert.assertTrue(insertInfo1.equals(getInfo1.get(0))); DataNodeInfo insertInfo2 = new DataNodeInfo("UUID2", "HOSTNAME", "www.ssm.com", 0, 0, null); DataNodeInfo insertInfo3 = new DataNodeInfo("UUID3", "HOSTNAME", "www.ssm.com", 0, 0, null); metaStore.insertDataNodeInfos(new DataNodeInfo[] {insertInfo2, insertInfo3}); List<DataNodeInfo> getInfo2 = metaStore.getDataNodeInfoByUuid("UUID2"); Assert.assertTrue(insertInfo2.equals(getInfo2.get(0))); List<DataNodeInfo> getInfo3 = metaStore.getDataNodeInfoByUuid("UUID3"); Assert.assertTrue(insertInfo3.equals(getInfo3.get(0))); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void deleteDataNodeInfo(String uuid) throws MetaStoreException { try { dataNodeInfoDao.delete(uuid); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testDeleteDataNodeInfo() throws Exception { DataNodeInfo insertInfo1 = new DataNodeInfo("UUID1", "hostname", "www.ssm.com", 100, 50, "lab"); DataNodeInfo insertInfo2 = new DataNodeInfo("UUID2", "HOSTNAME", "www.ssm.com", 0, 0, null); DataNodeInfo insertInfo3 = new DataNodeInfo("UUID3", "HOSTNAME", "www.ssm.com", 0, 0, null); metaStore.insertDataNodeInfos(new DataNodeInfo[] {insertInfo1, insertInfo2, insertInfo3}); List<DataNodeInfo> infos = metaStore.getAllDataNodeInfo(); Assert.assertTrue(infos.size() == 3); metaStore.deleteDataNodeInfo(insertInfo1.getUuid()); infos = metaStore.getAllDataNodeInfo(); Assert.assertTrue(infos.size() == 2); metaStore.deleteAllDataNodeInfo(); infos = metaStore.getAllDataNodeInfo(); Assert.assertTrue(infos.size() == 0); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo) throws MetaStoreException { try { dataNodeStorageInfoDao.insert(dataNodeStorageInfo); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testInsertDataNodeStorageInfo() throws Exception { DataNodeStorageInfo insertInfo1 = new DataNodeStorageInfo("UUID1", 10, 10, "storageid1", 0, 0, 0, 0, 0); metaStore.insertDataNodeStorageInfo(insertInfo1); List<DataNodeStorageInfo> getInfo1 = metaStore.getDataNodeStorageInfoByUuid("UUID1"); Assert.assertTrue(insertInfo1.equals(getInfo1.get(0))); DataNodeStorageInfo insertInfo2 = new DataNodeStorageInfo("UUID2", 10, 10, "storageid2", 0, 0, 0, 0, 0); DataNodeStorageInfo insertInfo3 = new DataNodeStorageInfo("UUID3", 10, 10, "storageid2", 0, 0, 0, 0, 0); metaStore.insertDataNodeStorageInfos(new DataNodeStorageInfo[] {insertInfo2, insertInfo3}); List<DataNodeStorageInfo> getInfo2 = metaStore.getDataNodeStorageInfoByUuid("UUID2"); Assert.assertTrue(insertInfo2.equals(getInfo2.get(0))); List<DataNodeStorageInfo> getInfo3 = metaStore.getDataNodeStorageInfoByUuid("UUID3"); Assert.assertTrue(insertInfo3.equals(getInfo3.get(0))); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void deleteDataNodeStorageInfo(String uuid) throws MetaStoreException { try { dataNodeStorageInfoDao.delete(uuid); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testDeleteDataNodeStorageInfo() throws Exception { DataNodeStorageInfo insertInfo1 = new DataNodeStorageInfo("UUID1", 10, 10, "storageid1", 0, 0, 0, 0, 0); DataNodeStorageInfo insertInfo2 = new DataNodeStorageInfo("UUID2", 10, 10, "storageid2", 0, 0, 0, 0, 0); DataNodeStorageInfo insertInfo3 = new DataNodeStorageInfo("UUID3", 10, 10, "storageid3", 0, 0, 0, 0, 0); metaStore.insertDataNodeStorageInfos( new DataNodeStorageInfo[] {insertInfo1, insertInfo2, insertInfo3}); List<DataNodeStorageInfo> infos = metaStore.getAllDataNodeStorageInfo(); Assert.assertTrue(infos.size() == 3); metaStore.deleteDataNodeStorageInfo(insertInfo1.getUuid()); infos = metaStore.getAllDataNodeStorageInfo(); Assert.assertTrue(infos.size() == 2); metaStore.deleteAllDataNodeStorageInfo(); infos = metaStore.getAllDataNodeStorageInfo(); Assert.assertTrue(infos.size() == 0); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { @Override public void deleteBackUpInfo(long rid) throws MetaStoreException { try { BackUpInfo backUpInfo = getBackUpInfo(rid); if (backUpInfo != null) { if (backUpInfoDao.getBySrc(backUpInfo.getSrc()).size() == 1) { if (setBackSrc != null) { setBackSrc.remove(backUpInfo.getSrc()); } } backUpInfoDao.delete(rid); } } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testDeleteBackUpInfo() throws MetaStoreException { BackUpInfo backUpInfo1 = new BackUpInfo(1, "test1", "test1", 1); metaStore.insertBackUpInfo(backUpInfo1); Assert.assertTrue(metaStore.srcInbackup("test1/dfafdsaf")); Assert.assertFalse(metaStore.srcInbackup("test2")); metaStore.deleteBackUpInfo(1); Assert.assertTrue(metaStore.listAllBackUpInfo().size() == 0); metaStore.insertBackUpInfo(backUpInfo1); metaStore.deleteAllBackUpInfo(); Assert.assertTrue(metaStore.listAllBackUpInfo().size() == 0); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void insertSystemInfo(SystemInfo systemInfo) throws MetaStoreException { try { if (systemInfoDao.containsProperty(systemInfo.getProperty())) { throw new Exception("The system property already exists"); } systemInfoDao.insert(systemInfo); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testInsertSystemInfo() throws MetaStoreException { SystemInfo systemInfo = new SystemInfo("test", "test"); metaStore.insertSystemInfo(systemInfo); Assert.assertTrue(metaStore.getSystemInfoByProperty("test").equals(systemInfo)); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void deleteSystemInfo( String property) throws MetaStoreException { try { systemInfoDao.delete(property); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testDeleteSystemInfo() throws MetaStoreException { SystemInfo systemInfo = new SystemInfo("test", "test"); metaStore.insertSystemInfo(systemInfo); metaStore.deleteSystemInfo("test"); Assert.assertTrue(metaStore.listAllSystemInfo().size() == 0); } |
MetaStore implements CopyMetaService, CmdletMetaService, BackupMetaService { public void updateSystemInfo( SystemInfo systemInfo) throws MetaStoreException { try { systemInfoDao.update(systemInfo); } catch (Exception e) { throw new MetaStoreException(e); } } MetaStore(DBPool pool); Connection getConnection(); DBType getDbType(); Long queryForLong(String sql); void insertFile(FileInfo file); void insertFiles(FileInfo[] files); int updateFileStoragePolicy(String path, String policyName); FileInfo getFile(long fid); FileInfo getFile(String path); List<FileInfo> getFile(); List<FileInfo> getFilesByPrefix(String path); List<FileInfo> getFilesByPrefixInOrder(String path); List<FileInfo> getFilesByPaths(Collection<String> paths); Map<String, Long> getFileIDs(Collection<String> paths); Map<Long, String> getFilePaths(Collection<Long> ids); List<FileAccessInfo> getHotFiles(
List<AccessCountTable> tables,
int topNum); void deleteAllFileInfo(); void deleteFileByPath(String path); List<AccessCountTable> getAllSortedTables(); void deleteAccessCountTable(
AccessCountTable table); void insertAccessCountTable(
AccessCountTable accessCountTable); void insertUpdateStoragesTable(StorageCapacity[] storages); void insertUpdateStoragesTable(List<StorageCapacity> storages); void insertUpdateStoragesTable(StorageCapacity storage); Map<String, StorageCapacity> getStorageCapacity(); void deleteStorage(String storageType); StorageCapacity getStorageCapacity(
String type); boolean updateStoragesTable(String type,
Long capacity, Long free); void insertStorageHistTable(StorageCapacity[] storages, long interval); List<StorageCapacity> getStorageHistoryData(String type, long interval,
long startTime, long endTime); void deleteStorageHistoryOldRecords(String type, long interval, long beforTimeStamp); void insertCachedFiles(long fid, String path,
long fromTime,
long lastAccessTime, int numAccessed); void insertCachedFiles(List<CachedFileStatus> s); void deleteAllCachedFile(); boolean updateCachedFiles(Long fid,
Long lastAccessTime,
Integer numAccessed); void updateCachedFiles(Map<String, Long> pathToIds,
List<FileAccessEvent> events); void deleteCachedFile(long fid); List<CachedFileStatus> getCachedFileStatus(); List<Long> getCachedFids(); CachedFileStatus getCachedFileStatus(
long fid); void createProportionTable(AccessCountTable dest,
AccessCountTable source); void dropTable(String tableName); void execute(String sql); void execute(List<String> statements); List<String> executeFilesPathQuery(
String sql); List<DetailedFileAction> listFileActions(long rid,
int size); List<DetailedFileAction> listFileActions(long rid, long start, long offset); long getNumFileAction(long rid); List<DetailedRuleInfo> listMoveRules(); List<DetailedRuleInfo> listSyncRules(); boolean insertNewRule(RuleInfo info); boolean updateRuleInfo(long ruleId, RuleState rs,
long lastCheckTime, long checkedCount, int commandsGen); boolean updateRuleState(long ruleId, RuleState rs); RuleInfo getRuleInfo(long ruleId); List<RuleInfo> listPageRule(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<RuleInfo> getRuleInfo(); List<CmdletInfo> listPageCmdlets(long rid, long start, long offset,
List<String> orderBy, List<Boolean> desc); long getNumCmdletsByRid(long rid); List<CmdletInfo> listPageCmdlets(long start, long offset,
List<String> orderBy, List<Boolean> desc); void deleteAllRules(); void insertCmdlets(CmdletInfo[] commands); void insertCmdlet(CmdletInfo command); long getMaxCmdletId(); @Override CmdletInfo getCmdletById(long cid); @Override List<CmdletInfo> getCmdlets(String cidCondition,
String ridCondition,
CmdletState state); List<CmdletInfo> getCmdlets(CmdletState state); boolean updateCmdlet(CmdletInfo cmdletInfo); @Override boolean updateCmdlet(long cid, CmdletState state); @Override boolean updateCmdlet(long cid, String parameters, CmdletState state); @Override void deleteCmdlet(long cid); void batchDeleteCmdlet(List<Long> cids); int deleteFinishedCmdletsWithGenTimeBefore(long timestamp); int deleteKeepNewCmdlets(long num); int getNumCmdletsInTerminiatedStates(); void insertActions(ActionInfo[] actionInfos); void insertAction(ActionInfo actionInfo); List<ActionInfo> listPageAction(long start, long offset, List<String> orderBy,
List<Boolean> desc); List<ActionInfo> searchAction(String path, long start,
long offset, List<String> orderBy, List<Boolean> desc,
long[] retTotalNumActions); void deleteCmdletActions(long cmdletId); void batchDeleteCmdletActions(List<Long> cmdletIds); void deleteAllActions(); void markActionFailed(long aid); void updateAction(ActionInfo actionInfo); void updateActions(ActionInfo[] actionInfos); List<ActionInfo> getNewCreatedActions(
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size); List<ActionInfo> getNewCreatedActions(String actionName,
int size, boolean successful,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
int size,
boolean finished); List<ActionInfo> getNewCreatedActions(String actionName,
boolean successful,
int size); List<ActionInfo> getActions(
List<Long> aids); List<ActionInfo> getActions(String aidCondition,
String cidCondition); List<ActionInfo> getActions(long rid, int size); List<ActionInfo> getActions(long rid, long start, long offset); ActionInfo getActionById(long aid); long getMaxActionId(); long getCountOfAllAction(); void insertStoragePolicy(StoragePolicy s); String getStoragePolicyName(int sid); Integer getStoragePolicyID(
String policyName); boolean insertXattrList(Long fid,
List<XAttribute> attributes); List<XAttribute> getXattrList(Long fid); @Override long insertFileDiff(FileDiff fileDiff); void insertFileDiffs(FileDiff[] fileDiffs); Long[] insertFileDiffs(List<FileDiff> fileDiffs); FileDiff getFileDiff(long did); List<FileDiff> getFileDiffsByFileName(String fileName); List<FileDiff> getFileDiffs(FileDiffState fileDiffState); @Override boolean updateFileDiff(long did,
FileDiffState state); boolean batchUpdateFileDiff(
List<Long> did, List<FileDiffState> states, List<String> parameters); boolean batchUpdateFileDiff(
List<Long> did, FileDiffState state); boolean updateFileDiff(long did,
FileDiffState state, String parameters); boolean updateFileDiff(long did,
String src); boolean updateFileDiff(FileDiff fileDiff); void updateFileDiff(List<FileDiff> fileDiffs); int getUselessFileDiffNum(); int deleteUselessFileDiff(int maxNumRecords); List<String> getSyncPath(int size); @Override List<FileDiff> getPendingDiff(); @Override List<FileDiff> getPendingDiff(long rid); @Override void deleteAllFileDiff(); void dropAllTables(); void initializeDataBase(); void checkTables(); int getTablesNum(String tableSet[]); void formatDataBase(); void aggregateTables(AccessCountTable destinationTable
, List<AccessCountTable> tablesToAggregate); void setClusterConfig(
ClusterConfig clusterConfig); void delClusterConfig(
ClusterConfig clusterConfig); List<ClusterConfig> listClusterConfig(); GlobalConfig getDefaultGlobalConfigByName(
String configName); void setGlobalConfig(
GlobalConfig globalConfig); void insertDataNodeInfo(DataNodeInfo dataNodeInfo); void insertDataNodeInfos(DataNodeInfo[] dataNodeInfos); void insertDataNodeInfos(List<DataNodeInfo> dataNodeInfos); List<DataNodeInfo> getDataNodeInfoByUuid(String uuid); List<DataNodeInfo> getAllDataNodeInfo(); void deleteDataNodeInfo(String uuid); void deleteAllDataNodeInfo(); void insertDataNodeStorageInfo(DataNodeStorageInfo dataNodeStorageInfo); void insertDataNodeStorageInfos(
DataNodeStorageInfo[] dataNodeStorageInfos); void insertDataNodeStorageInfos(
List<DataNodeStorageInfo> dataNodeStorageInfos); boolean judgeTheRecordIfExist(String storageType); long getStoreCapacityOfDifferentStorageType(String storageType); long getStoreFreeOfDifferentStorageType(String storageType); List<DataNodeStorageInfo> getDataNodeStorageInfoByUuid(String uuid); List<DataNodeStorageInfo> getAllDataNodeStorageInfo(); void deleteDataNodeStorageInfo(String uuid); void deleteAllDataNodeStorageInfo(); @Override List<BackUpInfo> listAllBackUpInfo(); boolean srcInbackup(String src); @Override BackUpInfo getBackUpInfo(long rid); List<BackUpInfo> getBackUpInfoBySrc(String src); @Override void deleteAllBackUpInfo(); @Override void deleteBackUpInfo(long rid); @Override void insertBackUpInfo(
BackUpInfo backUpInfo); List<ClusterInfo> listAllClusterInfo(); List<SystemInfo> listAllSystemInfo(); ClusterInfo getClusterInfoByCid(long id); SystemInfo getSystemInfoByProperty(
String property); boolean containSystemInfo(String property); void deleteAllClusterInfo(); void updateSystemInfo(
SystemInfo systemInfo); void updateAndInsertIfNotExist(
SystemInfo systemInfo); void deleteClusterInfo(long cid); void deleteSystemInfo(
String property); void insertClusterInfo(
ClusterInfo clusterInfo); void insertSystemInfo(SystemInfo systemInfo); void insertUpdateFileState(FileState fileState); void insertCompactFileStates(CompactFileState[] compactFileStates); FileState getFileState(String path); Map<String, FileState> getFileStates(List<String> paths); void deleteFileState(String filePath); void deleteCompactFileStates(List<String> paths); List<String> getSmallFilesByContainerFile(String containerFilePath); List<String> getAllContainerFiles(); } | @Test public void testUpdateSystemInfo() throws MetaStoreException { SystemInfo systemInfo = new SystemInfo("test", "test"); metaStore.insertSystemInfo(systemInfo); SystemInfo newSystemInfo = new SystemInfo("test", "test1"); metaStore.updateSystemInfo(newSystemInfo); Assert.assertTrue(metaStore.getSystemInfoByProperty("test").equals(newSystemInfo)); } |
ActionDao { public List<ActionInfo> getAPageOfAction(long start, long offset, List<String> orderBy, List<Boolean> isDesc) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); boolean ifHasAid = false; String sql = "SELECT * FROM " + TABLE_NAME + " ORDER BY "; for (int i = 0; i < orderBy.size(); i++) { if (orderBy.get(i).equals("aid")) { ifHasAid = true; } sql = sql + orderBy.get(i); if (isDesc.size() > i) { if (isDesc.get(i)) { sql = sql + " desc "; } sql = sql + ","; } } if (!ifHasAid) { sql = sql + "aid,"; } sql = sql.substring(0, sql.length() - 1); sql = sql + " LIMIT " + start + "," + offset + ";"; return jdbcTemplate.query(sql, new ActionRowMapper()); } ActionDao(DataSource dataSource); void setDataSource(DataSource dataSource); List<ActionInfo> getAll(); Long getCountOfAction(); ActionInfo getById(long aid); List<ActionInfo> getByIds(List<Long> aids); List<ActionInfo> getByCid(long cid); List<ActionInfo> getByCondition(String aidCondition,
String cidCondition); List<ActionInfo> getLatestActions(int size); List<ActionInfo> getLatestActions(String actionName, int size); List<ActionInfo> getLatestActions(String actionName, int size,
boolean successful, boolean finished); List<ActionInfo> getLatestActions(String actionName, boolean successful,
int size); List<ActionInfo> getAPageOfAction(long start, long offset, List<String> orderBy,
List<Boolean> isDesc); List<ActionInfo> getAPageOfAction(long start, long offset); List<ActionInfo> searchAction(String path, long start, long offset, List<String> orderBy,
List<Boolean> isDesc, long[] retTotalNumActions); List<ActionInfo> getLatestActions(String actionType, int size,
boolean finished); void delete(long aid); void deleteCmdletActions(long cid); int[] batchDeleteCmdletActions(final List<Long> cids); void deleteAll(); void insert(ActionInfo actionInfo); void insert(ActionInfo[] actionInfos); int[] replace(final ActionInfo[] actionInfos); int update(final ActionInfo actionInfo); int[] update(final ActionInfo[] actionInfos); long getMaxId(); } | @Test public void testGetAPageOfAction() { Map<String, String> args = new HashMap<>(); ActionInfo actionInfo = new ActionInfo(1, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100); ActionInfo actionInfo1 = new ActionInfo(2, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100); ActionInfo actionInfo2 = new ActionInfo(3, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100); ActionInfo actionInfo3 = new ActionInfo(4, 1, "cache", args, "Test", "Test", false, 123213213L, true, 123123L, 100); actionDao.insert(new ActionInfo[]{actionInfo, actionInfo1, actionInfo2, actionInfo3}); List<String> order = new ArrayList<>(); order.add("aid"); List<Boolean> desc = new ArrayList<>(); desc.add(false); Assert.assertTrue(actionDao.getAPageOfAction(2, 1, order, desc).get(0).equals(actionInfo2)); } |
NamespaceFetcher { public NamespaceFetcher(DFSClient client, MetaStore metaStore, ScheduledExecutorService service) { this(client, metaStore, DEFAULT_INTERVAL, service, new SmartConf()); } NamespaceFetcher(DFSClient client, MetaStore metaStore, ScheduledExecutorService service); NamespaceFetcher(DFSClient client, MetaStore metaStore, ScheduledExecutorService service, SmartConf conf); NamespaceFetcher(DFSClient client, MetaStore metaStore, long fetchInterval); NamespaceFetcher(DFSClient client, MetaStore metaStore, long fetchInterval,
ScheduledExecutorService service, SmartConf conf); void startFetch(); boolean fetchFinished(); void stop(); static final Logger LOG; } | @Test public void testNamespaceFetcher() throws IOException, InterruptedException, MissingEventsException, MetaStoreException { final Configuration conf = new SmartConf(); final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(2).build(); try { final DistributedFileSystem dfs = cluster.getFileSystem(); dfs.mkdir(new Path("/user"), new FsPermission("777")); dfs.create(new Path("/user/user1")); dfs.create(new Path("/user/user2")); dfs.mkdir(new Path("/tmp"), new FsPermission("777")); DFSClient client = dfs.getClient(); MetaStore adapter = Mockito.mock(MetaStore.class); final List<String> pathesInDB = new ArrayList<>(); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocationOnMock) { try { Object[] objects = invocationOnMock.getArguments(); for (FileInfo fileInfo : (FileInfo[]) objects[0]) { pathesInDB.add(fileInfo.getPath()); } } catch (Throwable t) { t.printStackTrace(); } return null; } }).when(adapter).insertFiles(any(FileInfo[].class)); NamespaceFetcher fetcher = new NamespaceFetcher(client, adapter, 100); fetcher.startFetch(); List<String> expected = Arrays.asList("/", "/user", "/user/user1", "/user/user2", "/tmp"); while (!fetcher.fetchFinished()) { Thread.sleep(100); } Assert.assertTrue(pathesInDB.size() == expected.size() && pathesInDB.containsAll(expected)); fetcher.stop(); } finally { cluster.shutdown(); } } |
InotifyEventApplier { public void apply(List<Event> events) throws IOException, MetaStoreException { List<String> statements = new ArrayList<>(); for (Event event : events) { List<String> gen = getSqlStatement(event); if (gen != null && !gen.isEmpty()){ for (String s : gen) { if (s != null && s.length() > 0) { statements.add(s); } } } } this.metaStore.execute(statements); } InotifyEventApplier(MetaStore metaStore, DFSClient client); void apply(List<Event> events); void apply(Event[] events); } | @Test public void testApplier() throws Exception { DFSClient client = Mockito.mock(DFSClient.class); FileInfo root = HadoopUtil.convertFileStatus(getDummyDirStatus("/", 1000), "/"); metaStore.insertFile(root); BackUpInfo backUpInfo = new BackUpInfo(1L, "/file", "remote/dest/", 10); metaStore.insertBackUpInfo(backUpInfo); InotifyEventApplier applier = new InotifyEventApplier(metaStore, client); Event.CreateEvent createEvent = new Event.CreateEvent.Builder() .iNodeType(Event.CreateEvent.INodeType.FILE) .ctime(1) .defaultBlockSize(1024) .groupName("cg1") .overwrite(true) .ownerName("user1") .path("/file") .perms(new FsPermission("777")) .replication(3) .build(); HdfsFileStatus status1 = new HdfsFileStatus( 0, false, 1, 1024, 0, 0, new FsPermission("777"), "owner", "group", new byte[0], new byte[0], 1010, 0, null, (byte) 0); Mockito.when(client.getFileInfo(Matchers.startsWith("/file"))).thenReturn(status1); Mockito.when(client.getFileInfo(Matchers.startsWith("/dir"))).thenReturn(getDummyDirStatus("", 1010)); applier.apply(new Event[] {createEvent}); FileInfo result1 = metaStore.getFile().get(1); Assert.assertEquals(result1.getPath(), "/file"); Assert.assertEquals(result1.getFileId(), 1010L); Assert.assertEquals(result1.getPermission(), 511); Event close = new Event.CloseEvent("/file", 1024, 0); applier.apply(new Event[] {close}); FileInfo result2 = metaStore.getFile().get(1); Assert.assertEquals(result2.getLength(), 1024); Assert.assertEquals(result2.getModificationTime(), 0L); Event meta = new Event.MetadataUpdateEvent.Builder() .path("/file") .metadataType(Event.MetadataUpdateEvent.MetadataType.TIMES) .mtime(2) .atime(3) .replication(4) .ownerName("user2") .groupName("cg2") .build(); applier.apply(new Event[] {meta}); FileInfo result4 = metaStore.getFile().get(1); Assert.assertEquals(result4.getAccessTime(), 3); Assert.assertEquals(result4.getModificationTime(), 2); Event meta1 = new Event.MetadataUpdateEvent.Builder() .path("/file") .metadataType(Event.MetadataUpdateEvent.MetadataType.OWNER) .ownerName("user1") .groupName("cg1") .build(); applier.apply(new Event[] {meta1}); result4 = metaStore.getFile().get(1); Assert.assertEquals(result4.getOwner(), "user1"); Assert.assertEquals(result4.getGroup(), "cg1"); Event.CreateEvent createEvent2 = new Event.CreateEvent.Builder() .iNodeType(Event.CreateEvent.INodeType.DIRECTORY) .ctime(1) .groupName("cg1") .overwrite(true) .ownerName("user1") .path("/dir") .perms(new FsPermission("777")) .replication(3) .build(); Event.CreateEvent createEvent3 = new Event.CreateEvent.Builder() .iNodeType(Event.CreateEvent.INodeType.FILE) .ctime(1) .groupName("cg1") .overwrite(true) .ownerName("user1") .path("/dir/file") .perms(new FsPermission("777")) .replication(3) .build(); Event rename = new Event.RenameEvent.Builder().dstPath("/dir2").srcPath("/dir").timestamp(5).build(); applier.apply(new Event[] {createEvent2, createEvent3, rename}); List<FileInfo> result5 = metaStore.getFile(); List<String> expectedPaths = Arrays.asList("/dir2", "/dir2/file", "/file"); List<String> actualPaths = new ArrayList<>(); for (FileInfo s : result5) { actualPaths.add(s.getPath()); } Collections.sort(actualPaths); Assert.assertTrue(actualPaths.size() == 4); Assert.assertTrue(actualPaths.containsAll(expectedPaths)); Event unlink = new Event.UnlinkEvent.Builder().path("/").timestamp(6).build(); applier.apply(new Event[]{unlink}); Thread.sleep(1200); Assert.assertEquals(metaStore.getFile().size(), 0); System.out.println("Files in table " + metaStore.getFile().size()); List<FileDiff> fileDiffList = metaStore.getPendingDiff(); Assert.assertTrue(fileDiffList.size() == 4); }
@Test public void testApplierCreateEvent() throws Exception { DFSClient client = Mockito.mock(DFSClient.class); InotifyEventApplier applier = new InotifyEventApplier(metaStore, client); BackUpInfo backUpInfo = new BackUpInfo(1L, "/file1", "remote/dest/", 10); metaStore.insertBackUpInfo(backUpInfo); HdfsFileStatus status1 = new HdfsFileStatus( 0, false, 2, 123, 0, 0, new FsPermission("777"), "test", "group", new byte[0], new byte[0], 1010, 0, null, (byte) 0); Mockito.when(client.getFileInfo("/file1")).thenReturn(status1); List<Event> events = new ArrayList<>(); Event.CreateEvent createEvent = new Event.CreateEvent.Builder().path("/file1").defaultBlockSize(123).ownerName("test") .replication(2).perms(new FsPermission(FsAction.NONE, FsAction.NONE, FsAction.NONE)).build(); events.add(createEvent); Mockito.when(client.getFileInfo("/file1")).thenReturn(status1); applier.apply(events); Assert.assertTrue(metaStore.getFile("/file1").getOwner().equals("test")); List<FileDiff> fileDiffs = metaStore.getFileDiffsByFileName("/file1"); Assert.assertTrue(fileDiffs.size() > 0); for (FileDiff fileDiff : fileDiffs) { if (fileDiff.getDiffType().equals(FileDiffType.APPEND)) { Assert.assertTrue(fileDiff.getParameters().get("-owner").equals("test")); } } }
@Test public void testApplierRenameEvent() throws Exception { DFSClient client = Mockito.mock(DFSClient.class); InotifyEventApplier applier = new InotifyEventApplier(metaStore, client); FileInfo[] fileInfos = new FileInfo[]{ HadoopUtil.convertFileStatus(getDummyFileStatus("/dirfile", 7000), "/dirfile"), HadoopUtil.convertFileStatus(getDummyDirStatus("/dir", 8000), "/dir"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir/file1", 8001), "/dir/file1"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir/file2", 8002), "/dir/file2"), HadoopUtil.convertFileStatus(getDummyDirStatus("/dir2", 8100), "/dir2"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir2/file1", 8101), "/dir2/file1"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir2/file2", 8102), "/dir2/file2"), HadoopUtil.convertFileStatus(getDummyDirStatus("/dir/dir", 8200), "/dir/dir"), HadoopUtil.convertFileStatus(getDummyFileStatus("/dir/dir/f1", 8201), "/dir/dir/f1"), }; metaStore.insertFiles(fileInfos); Mockito.when(client.getFileInfo("/dir1")).thenReturn(getDummyDirStatus("/dir1", 8000)); Event.RenameEvent dirRenameEvent = new Event.RenameEvent.Builder() .srcPath("/dir") .dstPath("/dir1") .build(); applier.apply(new Event[] {dirRenameEvent}); Assert.assertTrue(metaStore.getFile("/dir") == null); Assert.assertTrue(metaStore.getFile("/dir/file1") == null); Assert.assertTrue(metaStore.getFile("/dirfile") != null); Assert.assertTrue(metaStore.getFile("/dir1") != null); Assert.assertTrue(metaStore.getFile("/dir1/file1") != null); Assert.assertTrue(metaStore.getFile("/dir1/dir/f1") != null); Assert.assertTrue(metaStore.getFile("/dir2") != null); Assert.assertTrue(metaStore.getFile("/dir2/file1") != null); List<Event> events = new ArrayList<>(); Event.RenameEvent renameEvent = new Event.RenameEvent.Builder() .srcPath("/file1") .dstPath("/file2") .build(); events.add(renameEvent); applier.apply(events); Assert.assertTrue(metaStore.getFile("/file2") == null); Mockito.when(client.getFileInfo("/file2")).thenReturn(getDummyFileStatus("/file2", 2000)); applier.apply(events); FileInfo info = metaStore.getFile("/file2"); Assert.assertTrue(info != null && info.getFileId() == 2000); events.clear(); renameEvent = new Event.RenameEvent.Builder() .srcPath("/file2") .dstPath("/file3") .build(); events.add(renameEvent); applier.apply(events); FileInfo info2 = metaStore.getFile("/file2"); Assert.assertTrue(info2 == null); FileInfo info3 = metaStore.getFile("/file3"); Assert.assertTrue(info3 != null); renameEvent = new Event.RenameEvent.Builder() .srcPath("/file3") .dstPath("/file4") .build(); events.clear(); events.add(renameEvent); applier.apply(events); FileInfo info4 = metaStore.getFile("/file3"); FileInfo info5 = metaStore.getFile("/file4"); Assert.assertTrue(info4 == null && info5 != null); } |
ListFileAction extends HdfsAction { @Override public void init(Map<String, String> args) { super.init(args); this.srcPath = args.get(FILE_PATH); } @Override void init(Map<String, String> args); } | @Test public void testRemoteFileList() throws Exception { final String srcPath = "/testList"; final String file1 = "file1"; final String file2 = "file2"; final String dir = "/childDir"; final String dirFile1 = "childDirFile1"; dfs.mkdirs(new Path(srcPath)); dfs.mkdirs(new Path(srcPath + dir)); FSDataOutputStream out1 = dfs.create(new Path(dfs.getUri() + srcPath + "/" + file1)); out1.writeChars("test"); out1.close(); out1 = dfs.create(new Path(dfs.getUri() + srcPath + "/" + file2)); out1.writeChars("test"); out1.close(); out1 = dfs.create(new Path(dfs.getUri() + srcPath + dir + "/" + dirFile1)); out1.writeChars("test"); out1.close(); Assert.assertTrue(dfsClient.exists(srcPath + "/" + file1)); Assert.assertTrue(dfsClient.exists(srcPath + "/" + file2)); Assert.assertTrue(dfsClient.exists(srcPath + dir + "/" + dirFile1)); ListFileAction listFileAction = new ListFileAction(); listFileAction.setDfsClient(dfsClient); listFileAction.setContext(smartContext); Map<String , String> args = new HashMap<>(); args.put(ListFileAction.FILE_PATH , dfs.getUri() + srcPath); listFileAction.init(args); listFileAction.run(); Assert.assertTrue(listFileAction.getExpectedAfterRun()); listFileAction = new ListFileAction(); listFileAction.setDfsClient(dfsClient); listFileAction.setContext(smartContext); args = new HashMap<>(); args.put(ListFileAction.FILE_PATH , dfs.getUri() + srcPath + "/" + file1); listFileAction.init(args); listFileAction.run(); Assert.assertTrue(listFileAction.getExpectedAfterRun()); }
@Test public void testLocalFileList() throws Exception { final String srcPath = "/testList"; final String file1 = "file1"; final String file2 = "file2"; final String dir = "/childDir"; final String dirFile1 = "childDirFile1"; dfs.mkdirs(new Path(srcPath)); dfs.mkdirs(new Path(srcPath + dir)); FSDataOutputStream out1 = dfs.create(new Path(dfs.getUri() + srcPath + "/" + file1)); out1.writeChars("test"); out1.close(); out1 = dfs.create(new Path(srcPath + "/" + file2)); out1.writeChars("test"); out1.close(); out1 = dfs.create(new Path(srcPath + dir + "/" + dirFile1)); out1.writeChars("test"); out1.close(); Assert.assertTrue(dfsClient.exists(srcPath + "/" + file1)); Assert.assertTrue(dfsClient.exists(srcPath + "/" + file2)); Assert.assertTrue(dfsClient.exists(srcPath + dir + "/" + dirFile1)); ListFileAction listFileAction = new ListFileAction(); listFileAction.setDfsClient(dfsClient); listFileAction.setContext(smartContext); Map<String , String> args = new HashMap<>(); args.put(ListFileAction.FILE_PATH , srcPath); listFileAction.init(args); listFileAction.run(); Assert.assertTrue(listFileAction.getExpectedAfterRun()); listFileAction = new ListFileAction(); listFileAction.setDfsClient(dfsClient); listFileAction.setContext(smartContext); args = new HashMap<>(); args.put(ListFileAction.FILE_PATH , srcPath + "/" + file1); listFileAction.init(args); listFileAction.run(); Assert.assertTrue(listFileAction.getExpectedAfterRun()); } |
FileInfo { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FileInfo fileInfo = (FileInfo) o; return fileId == fileInfo.fileId && length == fileInfo.length && isdir == fileInfo.isdir && blockReplication == fileInfo.blockReplication && blocksize == fileInfo.blocksize && modificationTime == fileInfo.modificationTime && accessTime == fileInfo.accessTime && permission == fileInfo.permission && storagePolicy == fileInfo.storagePolicy && Objects.equals(path, fileInfo.path) && Objects.equals(owner, fileInfo.owner) && Objects.equals(group, fileInfo.group); } FileInfo(String path, long fileId, long length, boolean isdir,
short blockReplication, long blocksize, long modificationTime,
long accessTime, short permission, String owner, String group,
byte storagePolicy); String getPath(); void setPath(String path); long getFileId(); void setFileId(long fileId); long getLength(); void setLength(long length); boolean isdir(); void setIsdir(boolean isdir); short getBlockReplication(); void setBlockReplication(short blockReplication); long getBlocksize(); void setBlocksize(long blocksize); long getModificationTime(); void setModificationTime(long modificationTime); long getAccessTime(); void setAccessTime(long accessTime); short getPermission(); void setPermission(short permission); String getOwner(); void setOwner(String owner); String getGroup(); void setGroup(String group); byte getStoragePolicy(); void setStoragePolicy(byte storagePolicy); @Override boolean equals(Object o); @Override int hashCode(); static Builder newBuilder(); @Override String toString(); } | @Test public void testEquals() throws Exception { FileInfo fileInfo = new FileInfo(" ", 1, 1, true, (short) 1, 1, 1, 1, (short) 1, " ", " ", (byte) 1); Assert.assertEquals(true, fileInfo.equals(fileInfo)); FileInfo fileInfo1 = new FileInfo(" ", 1, 1, true, (short) 1, 1, 1, 1, (short) 1, " ", " ", (byte) 1); Assert.assertEquals(true, fileInfo.equals(fileInfo1)); FileInfo fileInfo2 = new FileInfo(" ", 1, 1, true, (short) 1, 1, 1, 1, (short) 1, null, " ", (byte) 1); Assert.assertEquals(false, fileInfo.equals(fileInfo2)); Assert.assertEquals(false, fileInfo2.equals(fileInfo)); FileInfo fileInfo3 = new FileInfo(null, 1, 1, true, (short) 1, 1, 1, 1, (short) 1, " ", " ", (byte) 1); Assert.assertEquals(false, fileInfo.equals(fileInfo3)); Assert.assertEquals(false, fileInfo3.equals(fileInfo)); FileInfo fileInfo4 = new FileInfo(null, 1, 1, true, (short) 1, 1, 1, 1, (short) 1, " ", null, (byte) 1); Assert.assertEquals(false, fileInfo.equals(fileInfo4)); Assert.assertEquals(false, fileInfo4.equals(fileInfo)); FileInfo fileInfo5 = new FileInfo(" ", 1, 1, true, (short) 1, 1, 1, 1, (short) 2, " ", " ", (byte) 1); Assert.assertEquals(false, fileInfo.equals(fileInfo5)); } |
StringUtil { public static List<String> parseCmdletString(String cmdlet) throws ParseException { if (cmdlet == null || cmdlet.length() == 0) { return new ArrayList<>(); } char[] chars = (cmdlet + " ").toCharArray(); List<String> blocks = new ArrayList<String>(); char c; char[] token = new char[chars.length]; int tokenlen = 0; boolean sucing = false; boolean string = false; for (int idx = 0; idx < chars.length; idx++) { c = chars[idx]; if (c == ' ' || c == '\t') { if (string) { token[tokenlen++] = c; } if (sucing) { blocks.add(String.valueOf(token, 0, tokenlen)); tokenlen = 0; sucing = false; } } else if (c == ';') { if (string) { throw new ParseException("Unexpected break of string", idx); } if (sucing) { blocks.add(String.valueOf(token, 0, tokenlen)); tokenlen = 0; sucing = false; } } else if (c == '\\') { boolean tempAdded = false; if (sucing || string) { token[tokenlen++] = chars[++idx]; tempAdded = true; } if (!tempAdded && !sucing) { sucing = true; token[tokenlen++] = chars[++idx]; } } else if (c == '"') { if (sucing) { throw new ParseException("Unexpected \"", idx); } if (string) { if (chars[idx + 1] != '"') { string = false; blocks.add(String.valueOf(token, 0, tokenlen)); tokenlen = 0; } else { idx++; } } else { string = true; } } else if (c == '\r' || c == '\n') { if (sucing) { sucing = false; blocks.add(String.valueOf(token, 0, tokenlen)); tokenlen = 0; } if (string) { throw new ParseException("String cannot in more than one line", idx); } } else { if (string) { token[tokenlen++] = chars[idx]; } else { sucing = true; token[tokenlen++] = chars[idx]; } } } if (string) { throw new ParseException("Unexpected tail of string", chars.length); } return blocks; } static String join(CharSequence delimiter,
Iterable<? extends CharSequence> elements); static String getBaseDir(String path); static String globString2SqlLike(String str); static long pharseTimeString(String str); static List<String> parseCmdletString(String cmdlet); } | @Test public void testCmdletString() throws Exception { Map<String, Integer> strs = new HashMap<>(); strs.put("int a b -c d -e f \"gg ' kk ' ff\" \" mn \"", 9); strs.put("cat /dir/file ", 2); List<String> items; for (String str : strs.keySet()) { items = StringUtil.parseCmdletString(str); Assert.assertTrue(strs.get(str) == items.size()); System.out.println(items.size() + " -> " + str); } } |
SecurityUtil { public static void loginUsingKeytab(SmartConf conf) throws IOException{ String keytabFilename = conf.get(SmartConfKeys.SMART_SERVER_KEYTAB_FILE_KEY); if (keytabFilename == null || keytabFilename.length() == 0) { throw new IOException("Running in secure mode, but config doesn't have a keytab"); } File keytabPath = new File(keytabFilename); String principal = conf.get(SmartConfKeys.SMART_SERVER_KERBEROS_PRINCIPAL_KEY); try { SecurityUtil.loginUsingKeytab(principal, keytabPath.getAbsolutePath()); } catch (IOException e) { LOG.error("Fail to login using keytab. " + e); throw new IOException("Fail to login using keytab. " + e); } LOG.info("Login successful for user: " + principal); } static synchronized Subject loginUserFromTgtTicket(String smartSecurity); static Subject loginUsingTicketCache(String principal); static void loginUsingKeytab(SmartConf conf); static void loginUsingKeytab(String keytabFilename, String principal); static Subject loginUsingKeytab(
String principal, File keytabFile); static Configuration useTicketCache(String principal, String ticketCacheFileName); static Configuration useKeytab(String principal, File keytabFile); static boolean isSecurityEnabled(SmartConf conf); static final Logger LOG; static final boolean ENABLE_DEBUG; } | @Test public void loginUsingKeytab() throws Exception { File keytabFile = generateKeytab(keytabFileName, principal); Subject subject = SecurityUtil.loginUsingKeytab(principal, keytabFile); Assert.assertEquals(principal, subject.getPrincipals().iterator().next().getName()); System.out.println("Login successful for user: " + subject.getPrincipals().iterator().next()); } |
CustomerOrderExtractor implements PayloadWrapperExtractor<CustomerOrderPayload, CustomerOrder> { @Override public CustomerOrder extractData(PayloadWrapper<CustomerOrderPayload> payloadWrapper) { CustomerOrder value = null; if (payloadWrapper.hasPayload()) { value = new CustomerOrder(); CustomerOrderPayload payload = payloadWrapper.getPayload(); value.setCustomerId(payload.getCustomerId()); value.setShippingAddress(payload.getShippingAddress()); value.setOrderDate(payload.getOrderDate()); value.setItemSet(payload.getItemSet()); } return value; } @Override CustomerOrder extractData(PayloadWrapper<CustomerOrderPayload> payloadWrapper); } | @Test public void testExtractData() { CustomerOrderExtractor extractor = new CustomerOrderExtractor(); PayloadWrapper<CustomerOrderPayload> payloadWrapper = new PayloadWrapper<CustomerOrderPayload>(null); assertThat(extractor.extractData(payloadWrapper)).isNull(); Date orderDate = new Date(); List<String> items = Arrays.asList("item1", "item2"); CustomerOrderPayload payload = new CustomerOrderPayload(); payload.setId("id"); payload.setCustomerId("customerId"); payload.setOrderDate(orderDate.getTime()); payload.setShippingAddress("shippingAddress"); payload.setItemSet(new HashSet<>(items)); payloadWrapper = new PayloadWrapper<CustomerOrderPayload>(payload); CustomerOrder expected = new CustomerOrder(); expected.setCustomerId("customerId"); expected.setOrderDate(orderDate.getTime()); expected.setShippingAddress("shippingAddress"); expected.setItemSet(new HashSet<>(items)); assertThat(extractor.extractData(payloadWrapper)).isEqualTo(expected); } |
ItemExtractor implements PayloadWrapperExtractor<ItemPayload, Item> { @Override public Item extractData(PayloadWrapper<ItemPayload> payloadWrapper) { Item value = null; if (payloadWrapper.hasPayload()) { value = new Item(); ItemPayload payload = payloadWrapper.getPayload(); value.setName(payload.getName()); value.setDescription(payload.getDescription()); value.setPrice(payload.getPrice().toString()); } return value; } @Override Item extractData(PayloadWrapper<ItemPayload> payloadWrapper); } | @Test public void testExtractData() { ItemExtractor extractor = new ItemExtractor(); PayloadWrapper<ItemPayload> payloadWrapper = new PayloadWrapper<ItemPayload>(null); assertThat(extractor.extractData(payloadWrapper)).isNull(); ItemPayload payload = new ItemPayload(); payload.setId("id"); payload.setName("name"); payload.setDescription("description"); payload.setPrice(new BigDecimal("9.99")); payloadWrapper = new PayloadWrapper<ItemPayload>(payload); Item expected = new Item(); expected.setName("name"); expected.setDescription("description"); expected.setPrice("9.99"); assertThat(extractor.extractData(payloadWrapper)).isEqualTo(expected); } |
CustomerExtractor implements PayloadWrapperExtractor<CustomerPayload, Customer> { @Override public Customer extractData(PayloadWrapper<CustomerPayload> payloadWrapper) { Customer value = null; if (payloadWrapper.hasPayload()) { value = new Customer(); CustomerPayload payload = payloadWrapper.getPayload(); value.setName(payload.getName()); } return value; } @Override Customer extractData(PayloadWrapper<CustomerPayload> payloadWrapper); } | @Test public void testExtractData() { CustomerExtractor extractor = new CustomerExtractor(); PayloadWrapper<CustomerPayload> payloadWrapper = new PayloadWrapper<CustomerPayload>(null); assertThat(extractor.extractData(payloadWrapper)).isNull(); CustomerPayload payload = new CustomerPayload(); payload.setId("id"); payload.setName("name"); payloadWrapper = new PayloadWrapper<CustomerPayload>(payload); Customer expected = new Customer(); expected.setName("name"); assertThat(extractor.extractData(payloadWrapper)).isEqualTo(expected); } |
ItemResultSetExtractor implements ResultSetExtractor<PayloadWrapper<ItemPayload>> { @Override public PayloadWrapper<ItemPayload> extractData(ResultSet rs) throws SQLException, DataAccessException { ItemPayload itemPayload = null; if (rs.next()) { itemPayload = new ItemPayload(); itemPayload.setId(rs.getString("ID")); itemPayload.setName(rs.getString("NAME")); itemPayload.setPrice(rs.getBigDecimal("PRICE")); itemPayload.setDescription(rs.getString("DESCRIPTION")); } return new PayloadWrapper<>(itemPayload); } @Override PayloadWrapper<ItemPayload> extractData(ResultSet rs); } | @Test public void testExtractData() throws SQLException { ItemResultSetExtractor extractor = new ItemResultSetExtractor(); ResultSet rs = mock(ResultSet.class); given(rs.next()).willReturn(true).willReturn(false); given(rs.getString("ID")).willReturn("item1"); given(rs.getString("NAME")).willReturn("item name"); given(rs.getString("DESCRIPTION")).willReturn("description"); given(rs.getBigDecimal("PRICE")).willReturn(new BigDecimal("1.99")); ItemPayload payload = new ItemPayload(); payload.setId("item1"); payload.setName("item name"); payload.setDescription("description"); payload.setPrice(new BigDecimal("1.99")); PayloadWrapper<ItemPayload> payloadWrapper = new PayloadWrapper<ItemPayload>(payload); assertThat(extractor.extractData(rs)).isEqualTo(payloadWrapper); } |
CustomerResultSetExtractor implements ResultSetExtractor<PayloadWrapper<CustomerPayload>> { @Override public PayloadWrapper<CustomerPayload> extractData(ResultSet rs) throws SQLException, DataAccessException { CustomerPayload customerPayload = null; if (rs.next()) { customerPayload = new CustomerPayload(); customerPayload.setId(rs.getString("ID")); customerPayload.setName(rs.getString("NAME")); } return new PayloadWrapper<>(customerPayload); } @Override PayloadWrapper<CustomerPayload> extractData(ResultSet rs); } | @Test public void testExtractData() throws DataAccessException, SQLException { CustomerResultSetExtractor extractor = new CustomerResultSetExtractor(); ResultSet rs = mock(ResultSet.class); given(rs.next()).willReturn(true).willReturn(false); given(rs.getString("ID")).willReturn("customer1"); given(rs.getString("NAME")).willReturn("customer name"); CustomerPayload payload = new CustomerPayload(); payload.setId("customer1"); payload.setName("customer name"); PayloadWrapper<CustomerPayload> payloadWrapper = new PayloadWrapper<CustomerPayload>(payload); assertThat(extractor.extractData(rs)).isEqualTo(payloadWrapper); } |
CustomerOrderResultSetExtractor implements ResultSetExtractor<PayloadWrapper<CustomerOrderPayload>> { @Override public PayloadWrapper<CustomerOrderPayload> extractData(ResultSet rs) throws SQLException, DataAccessException { CustomerOrderPayload result = null; while (rs.next()) { if (result == null) { result = new CustomerOrderPayload(); result.setId(rs.getString("ID")); result.setCustomerId(rs.getString("CUSTOMER_ID")); result.setShippingAddress(rs.getString("S_ADDRESS")); result.setOrderDate(rs.getDate("ORDER_TS").getTime()); result.setItemSet(new HashSet<String>()); } result.getItemSet().add(rs.getString("ITEM_ID")); } return new PayloadWrapper<>(result); } @Override PayloadWrapper<CustomerOrderPayload> extractData(ResultSet rs); } | @Test public void testExtractData() throws DataAccessException, SQLException { Date orderDate = new Date(12345L); List<String> items = Arrays.asList("item1", "item2"); CustomerOrderResultSetExtractor extractor = new CustomerOrderResultSetExtractor(); ResultSet rs = mock(ResultSet.class); given(rs.next()).willReturn(true).willReturn(true).willReturn(false); given(rs.getString("ID")).willReturn("order1"); given(rs.getString("CUSTOMER_ID")).willReturn("customer1"); given(rs.getString("S_ADDRESS")).willReturn("address"); given(rs.getDate("ORDER_TS")).willReturn(orderDate); given(rs.getString("ITEM_ID")).willReturn("item1").willReturn("item2"); CustomerOrderPayload payload = new CustomerOrderPayload(); payload.setId("order1"); payload.setCustomerId("customer1"); payload.setOrderDate(orderDate.getTime()); payload.setShippingAddress("address"); payload.setItemSet(new HashSet<>(items)); PayloadWrapper<CustomerOrderPayload> payloadWrapper = new PayloadWrapper<CustomerOrderPayload>(payload); assertThat(extractor.extractData(rs)).isEqualTo(payloadWrapper); } |
GeodeMessageAggregator { @Aggregator public GeodeDataWrapper output(List<Message<PayloadWrapper>> messages) { GeodeDataWrapper geodeDataWrapper = new GeodeDataWrapper(); for (Message<PayloadWrapper> message : messages) { String geodeRegionName = (String) message.getHeaders().get("srcGroup"); Object geodeKey = message.getHeaders().get("srcKey"); PayloadWrapper<?> payloadWrapper = message.getPayload(); PayloadWrapperExtractor extractor = (PayloadWrapperExtractor) context.getBean(geodeRegionName + "Extractor"); if(payloadWrapper.hasPayload()){ geodeDataWrapper.getKeySetForRemove().remove(geodeKey); geodeDataWrapper.getDataMapForPut().put(geodeKey, extractor.extractData(payloadWrapper)); } else { geodeDataWrapper.getDataMapForPut().remove(geodeKey); geodeDataWrapper.getKeySetForRemove().add(geodeKey); } } return geodeDataWrapper; } GeodeMessageAggregator(ApplicationContext context, int groupCount, int batchSize); @Aggregator GeodeDataWrapper output(List<Message<PayloadWrapper>> messages); @CorrelationStrategy String correlation(Message<?> message); @ReleaseStrategy boolean canMessagesBeReleased(List<Message<?>> messages); } | @Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testOutput() { List<Message<PayloadWrapper>> messages = new ArrayList<>(); Message<PayloadWrapper> message1 = MessageBuilder .withPayload(new PayloadWrapper(new Object())) .setHeader("srcGroup", "foo") .setHeader("srcKey", "key1") .build(); messages.add(message1); Message<PayloadWrapper> message2 = MessageBuilder .withPayload(new PayloadWrapper(new Object())) .setHeader("srcGroup", "foo") .setHeader("srcKey", "key2") .build(); messages.add(message2); Message<PayloadWrapper> message3 = MessageBuilder .withPayload(new PayloadWrapper(null)) .setHeader("srcGroup", "foo") .setHeader("srcKey", "key1") .build(); messages.add(message3); GeodeDataWrapper geodeDataWrapper = geodeMessageAggregator.output(messages); assertThat(geodeDataWrapper.getDataMapForPut().containsKey("key1"), is(false)); assertThat(geodeDataWrapper.getDataMapForPut().containsKey("key2"), is(true)); } |
GeodeMessageAggregator { @CorrelationStrategy public String correlation(Message<?> message) { int hashCode = message.getHeaders().get("srcKey").hashCode(); int divisor = groupCount; return "[" + (String) message.getHeaders().get("srcGroup") + "]" + ",[" + Math.floorMod(hashCode, divisor) + "]"; } GeodeMessageAggregator(ApplicationContext context, int groupCount, int batchSize); @Aggregator GeodeDataWrapper output(List<Message<PayloadWrapper>> messages); @CorrelationStrategy String correlation(Message<?> message); @ReleaseStrategy boolean canMessagesBeReleased(List<Message<?>> messages); } | @Test public void testCorrelation() { Message<PayloadWrapper<Object>> message = MessageBuilder .withPayload(new PayloadWrapper<Object>(new Object())) .setHeader("srcGroup", "foo") .setHeader("srcKey", "key1") .build(); String expectedResult = "[foo],[" + Math.floorMod("key1".hashCode(), groupCount) + "]"; assertThat(geodeMessageAggregator.correlation(message), is(expectedResult)); } |
GeodeMessageAggregator { @ReleaseStrategy public boolean canMessagesBeReleased(List<Message<?>> messages) { return messages.size() >= batchSize; } GeodeMessageAggregator(ApplicationContext context, int groupCount, int batchSize); @Aggregator GeodeDataWrapper output(List<Message<PayloadWrapper>> messages); @CorrelationStrategy String correlation(Message<?> message); @ReleaseStrategy boolean canMessagesBeReleased(List<Message<?>> messages); } | @Test public void testCanMessagesBeReleased() { List<Message<?>> messages = new ArrayList<>(); Message<PayloadWrapper<Object>> message1 = MessageBuilder .withPayload(new PayloadWrapper<Object>(null)) .setHeader("srcGroup", "foo") .setHeader("srcKey", "key1") .build(); messages.add(message1); assertThat(geodeMessageAggregator.canMessagesBeReleased(messages), is(false)); Message<PayloadWrapper<Object>> message2 = MessageBuilder .withPayload(new PayloadWrapper<>(new Object())) .setHeader("srcGroup", "foo") .setHeader("srcKey", "key2") .build(); messages.add(message2); assertThat(geodeMessageAggregator.canMessagesBeReleased(messages), is(true)); } |
GeodeMessageHandler { public void handleMessage(Message<GeodeDataWrapper> message) { MessageHeaders headers = message.getHeaders(); GeodeDataWrapper payload = message.getPayload(); String regionName = (String) headers.get("srcGroup"); Region<Object, Object> region = clientCache.getRegion(regionName); region.putAll(payload.getDataMapForPut()); region.removeAll(payload.getKeySetForRemove()); } GeodeMessageHandler(ClientCache clientCache); void handleMessage(Message<GeodeDataWrapper> message); } | @Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testHandleMessage() { GeodeDataWrapper geodeDataWrapper = new GeodeDataWrapper(); geodeDataWrapper.getDataMapForPut().put("key1", "value1"); geodeDataWrapper.getDataMapForPut().put("key2", "value2"); geodeDataWrapper.getKeySetForRemove().add("key1"); Message<GeodeDataWrapper> message = MessageBuilder .withPayload(geodeDataWrapper) .setHeader("srcGroup", "foo") .build(); geodeMessageHandler.handleMessage(message); ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class); verify(region, times(1)).putAll(mapCaptor.capture()); assertThat(geodeDataWrapper.getDataMapForPut(), is(mapCaptor.getValue())); ArgumentCaptor<Set> setCaptor = ArgumentCaptor.forClass(Set.class); verify(region, times(1)).removeAll(setCaptor.capture()); assertThat(geodeDataWrapper.getDataMapForPut(), is(mapCaptor.getValue())); } |
DropboxAPI { public Account accountInfo() throws DropboxException { assertAuthenticated(); @SuppressWarnings("unchecked") Map<String, Object> accountInfo = (Map<String, Object>) RESTUtility.request(RequestMethod.GET, session.getAPIServer(), "/account/info", VERSION, new String[] {"locale", session.getLocale().toString()}, session); return new Account(accountInfo); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void accountInfo() throws Exception { Account info = api.accountInfo(); assert info.country != null : "No country for account"; assert info.displayName != null : "No displayName for account"; assert info.quota > 0 : "0 quota in account"; assert info.quotaNormal > 0 : "0 normal quota in account"; assert info.referralLink != null : "No referral link for account"; assert info.uid > 0 : "No uid for account"; } |
DropboxAPI { public Entry copy(String fromPath, String toPath) throws DropboxException { assertAuthenticated(); String[] params = {"root", session.getAccessType().toString(), "from_path", fromPath, "to_path", toPath, "locale", session.getLocale().toString()}; @SuppressWarnings("unchecked") Map<String, Object> resp = (Map<String, Object>)RESTUtility.request( RequestMethod.POST, session.getAPIServer(), "/fileops/copy", VERSION, params, session); return new Entry(resp); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void copy() throws Exception { String fromPath = TESTS_DIR + "/copyFrom.jpg"; String toPath = TESTS_DIR + "/copyTo.jpg"; uploadFile(frog, fromPath); Entry ent = api.copy(fromPath, toPath); assertFile(ent, frog, toPath); ent = api.metadata(toPath, 1, null, false, null); assertFile(ent, frog, toPath); } |
DropboxAPI { public Entry move(String fromPath, String toPath) throws DropboxException { assertAuthenticated(); String[] params = {"root", session.getAccessType().toString(), "from_path", fromPath, "to_path", toPath, "locale", session.getLocale().toString()}; @SuppressWarnings("unchecked") Map<String, Object> resp = (Map<String, Object>)RESTUtility.request( RequestMethod.POST, session.getAPIServer(), "/fileops/move", VERSION, params, session); return new Entry(resp); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void move() throws Exception { String fromPath = TESTS_DIR + "/moveFrom.jpg"; String toPath = TESTS_DIR + "/moveTo.jpg"; uploadFile(frog, fromPath); Entry moveEnt = api.move(fromPath, toPath); assertFile(moveEnt, frog, toPath); moveEnt = api.metadata(toPath, 1, null, false, null); assertFile(moveEnt, frog, toPath); Entry oldEnt = api.metadata(fromPath, 1, null, false, null); assertEquals(oldEnt.isDeleted, true); assertEquals(oldEnt.bytes, 0); assert oldEnt.isDeleted; } |
DropboxAPI { public DropboxLink media(String path, boolean ssl) throws DropboxException { assertAuthenticated(); String target = "/media/" + session.getAccessType() + path; @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>)RESTUtility.request(RequestMethod.GET, session.getAPIServer(), target, VERSION, new String[] {"locale", session.getLocale().toString()}, session); return new DropboxLink(map, ssl); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void media() throws Exception { String path = TESTS_DIR + "/dropbox_song.mp3"; uploadFile(song, path); DropboxLink link = api.media(path, true); assert link.url != null : "No url for streamed file"; link = api.media(path, false); assert link.url != null : "No insecure url for streamed file"; } |
DropboxAPI { public DropboxLink share(String path) throws DropboxException { assertAuthenticated(); String target = "/shares/" + session.getAccessType() + path; @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>)RESTUtility.request(RequestMethod.GET, session.getAPIServer(), target, VERSION, new String[] {"locale", session.getLocale().toString()}, session); String url = (String)map.get("url"); Date expires = RESTUtility.parseDate((String)map.get("expires")); if (url == null || expires == null) { throw new DropboxParseException("Could not parse share response."); } return new DropboxLink(map); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void share() throws Exception{ String path = TESTS_DIR + "/dropbox_song.mp3"; uploadFile(song, path); DropboxLink link = api.share(path); assert link.url != null : "No url for streamed file"; } |
DropboxAPI { public List<Entry> search(String path, String query, int fileLimit, boolean includeDeleted) throws DropboxException { assertAuthenticated(); if (fileLimit <= 0) { fileLimit = SEARCH_DEFAULT_LIMIT; } String target = "/search/" + session.getAccessType() + path; String[] params = { "query", query, "file_limit", String.valueOf(fileLimit), "include_deleted", String.valueOf(includeDeleted), "locale", session.getLocale().toString() }; Object response = RESTUtility.request(RequestMethod.GET, session.getAPIServer(), target, VERSION, params, session); ArrayList<Entry> ret = new ArrayList<Entry>(); if (response instanceof JSONArray) { JSONArray jresp = (JSONArray)response; for (Object next: jresp) { if (next instanceof Map) { @SuppressWarnings("unchecked") Entry ent = new Entry((Map<String, Object>)next); ret.add(ent); } } } return ret; } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void search() throws Exception { try { api.search("/", "", 1000, false); assert false: "Short (empty) search string did not throw an error."; } catch (DropboxServerException e) { if (e.error != DropboxServerException._400_BAD_REQUEST) { assert false: "Unexpected Dropbox Error: " + e.toString(); } } String searchDir = TESTS_DIR + "/searchDir/"; uploadFile(foo, searchDir + "text.txt"); uploadFile(foo, searchDir + "subFolder/text.txt"); uploadFile(foo, searchDir + "subFolder/cow.txt"); uploadFile(frog, searchDir + "frog.jpg"); uploadFile(frog, searchDir + "frog2.jpg"); uploadFile(frog, searchDir + "subFolder/frog2.jpg"); List<Entry> results = api.search(searchDir, "sadfasdf", 1000, false); assertEquals(results.size(), 0); results = api.search(searchDir, "jpg", 1000, false); assertEquals(results.size(), 3); assertFile(results.get(0), frog, searchDir + "frog.jpg"); assertFile(results.get(1), frog, searchDir + "frog2.jpg"); assertFile(results.get(2), frog, searchDir + "subFolder/frog2.jpg"); results = api.search(searchDir + "subFolder", "jpg", 1000, false); assertEquals(results.size(), 1); assertFile(results.get(0), frog, searchDir + "subFolder/frog2.jpg"); } |
DropboxAPI { public Entry metadata(String path, int fileLimit, String hash, boolean list, String rev) throws DropboxException { assertAuthenticated(); if (fileLimit <= 0) { fileLimit = METADATA_DEFAULT_LIMIT; } String[] params = { "file_limit", String.valueOf(fileLimit), "hash", hash, "list", String.valueOf(list), "rev", rev, "locale", session.getLocale().toString() }; String url_path = "/metadata/" + session.getAccessType() + path; @SuppressWarnings("unchecked") Map<String, Object> dirinfo = (Map<String, Object>) RESTUtility.request(RequestMethod.GET, session.getAPIServer(), url_path, VERSION, params, session); return new Entry(dirinfo); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void getMetadataBad() throws Exception { try { String path = TESTS_DIR + "iDoNotExist.txt"; Entry ent = api.metadata(path, 1000, null, true, null); assert ent.isDeleted: "The " + path + " directory should not exist"; } catch (DropboxServerException e) { if (e.error != DropboxServerException._404_NOT_FOUND) { assert false: "Unexpected Dropbox Server Error: " + e.toString(); } } catch (DropboxException e) { assert false: "Unexpected Dropbox Error: " + e.toString(); } }
@Test public void getMetadata() throws Exception { String path = TESTS_DIR + "/metadatasong.mp3"; uploadFile(song, path); api.metadata(path, 1000, null, true, null); }
@Test public void getMetadataCached() throws Exception { try { Entry ent = api.metadata(TESTS_DIR, 1000, null, true, null); api.metadata(TESTS_DIR, 1000, ent.hash, true, null); assert false : "Directory should have been cached"; } catch (DropboxServerException e) { if (e.error != DropboxServerException._304_NOT_MODIFIED) { assert false: "Unexpected Dropbox Server Error: " + e.toString(); } } catch (DropboxException e) { assert false: "Unexpected Dropbox Error: " + e.toString(); } } |
DropboxAPI { public Entry createFolder(String path) throws DropboxException { assertAuthenticated(); String[] params = {"root", session.getAccessType().toString(), "path", path, "locale", session.getLocale().toString()}; @SuppressWarnings("unchecked") Map<String, Object> resp = (Map<String, Object>) RESTUtility.request( RequestMethod.POST, session.getAPIServer(), "/fileops/create_folder", VERSION, params, session); return new Entry(resp); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void createFolder() throws Exception { String path = TESTS_DIR + "createdFolder"; Entry ent = api.createFolder(path); assertEquals(ent.isDir, true); }
@Test public void createFolderDupe() throws Exception { try { api.createFolder(TESTS_DIR); assert false : "Able to create duplicate folder"; } catch (DropboxServerException e) { if (e.error != DropboxServerException._403_FORBIDDEN) { assert false: "Unexpected Dropbox Server Error: " + e.toString(); } } catch (DropboxException e) { assert false: "Unexpected Dropbox Error: " + e.toString(); } } |
DropboxAPI { public Entry putFile(String path, InputStream is, long length, String parentRev, ProgressListener listener) throws DropboxException { UploadRequest request = putFileRequest(path, is, length, parentRev, listener); return request.upload(); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void putFile() throws Exception { assertPutFile(foo, TESTS_DIR + "/putfoo.txt"); assertPutFile(frog, TESTS_DIR + "/putfrog.jpg"); assertPutFile(song, TESTS_DIR + "/putsong.mp3"); } |
DropboxAPI { public DropboxFileInfo getFile(String path, String rev, OutputStream os, ProgressListener listener) throws DropboxException { DropboxInputStream dis = getFileStream(path, rev); dis.copyStreamToOutput(os, listener); return dis.getFileInfo(); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void getFile() throws Exception { assertGetFile(foo, TESTS_DIR + "/getfoo.txt"); assertGetFile(song, TESTS_DIR + "/getsong.mp3"); assertGetFile(frog, TESTS_DIR + "/getfrog.jpg"); } |
DropboxAPI { public DropboxFileInfo getThumbnail(String path, OutputStream os, ThumbSize size, ThumbFormat format, ProgressListener listener) throws DropboxException { DropboxInputStream thumb = getThumbnailStream(path, size, format); thumb.copyStreamToOutput(os, listener); return thumb.getFileInfo(); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void getThumbnail() throws Exception { String path = TESTS_DIR + "/thumbnailfrog.jpg"; uploadFile(frog, path); OutputStream out = new ByteArrayOutputStream(); DropboxFileInfo info = api.getThumbnail(path, out, ThumbSize.BESTFIT_480x320, ThumbFormat.JPEG, null); assert info != null : "No info returned"; assert info.getFileSize() > 0 : "Thumbnail length 0"; assert info.getMetadata().bytes > 0 : "Original file size 0"; assert info.getFileSize() != info.getMetadata().bytes : "Thumbnail equals original file size."; } |
DropboxAPI { public DropboxInputStream getThumbnailStream(String path, ThumbSize size, ThumbFormat format) throws DropboxException { assertAuthenticated(); String target = "/thumbnails/" + session.getAccessType() + path; String[] params = {"size", size.toAPISize(), "format", format.toString(), "locale", session.getLocale().toString()}; RequestAndResponse rr = RESTUtility.streamRequest(RequestMethod.GET, session.getContentServer(), target, VERSION, params, session); return new DropboxInputStream(rr.request, rr.response); } DropboxAPI(SESS_T session); ChunkedUploader getChunkedUploader(InputStream is, long length); ChunkedUploader getChunkedUploader(InputStream is, long length, int chunkSize); ChunkedUploadRequest chunkedUploadRequest(InputStream is, long length,
ProgressListener listener,
long offset, String uploadId); SESS_T getSession(); Account accountInfo(); DropboxFileInfo getFile(String path, String rev, OutputStream os,
ProgressListener listener); DropboxInputStream getFileStream(String path, String rev); Entry putFile(String path, InputStream is, long length,
String parentRev, ProgressListener listener); UploadRequest putFileRequest(String path, InputStream is,
long length, String parentRev, ProgressListener listener); Entry putFileOverwrite(String path, InputStream is, long length,
ProgressListener listener); UploadRequest putFileOverwriteRequest(String path, InputStream is,
long length, ProgressListener listener); DropboxFileInfo getThumbnail(String path, OutputStream os,
ThumbSize size, ThumbFormat format, ProgressListener listener); DropboxInputStream getThumbnailStream(String path, ThumbSize size,
ThumbFormat format); Entry metadata(String path, int fileLimit, String hash,
boolean list, String rev); @SuppressWarnings("unchecked") List<Entry> revisions(String path, int revLimit); List<Entry> search(String path, String query, int fileLimit,
boolean includeDeleted); Entry move(String fromPath, String toPath); Entry copy(String fromPath, String toPath); Entry createFolder(String path); void delete(String path); Entry restore(String path, String rev); DropboxLink media(String path, boolean ssl); DropboxLink share(String path); DeltaPage<Entry> delta(String cursor); CreatedCopyRef createCopyRef(String sourcePath); Entry addFromCopyRef(String sourceCopyRef, String targetPath); static final int VERSION; static final String SDK_VERSION; static final long MAX_UPLOAD_SIZE; } | @Test public void getThumbnailStream() throws Exception { String path = TESTS_DIR + "/thumbnailstreamfrog.jpg"; uploadFile(frog, path); DropboxInputStream is = api.getThumbnailStream(path, ThumbSize.BESTFIT_480x320, ThumbFormat.JPEG); assert is != null : "No info returned"; assert is.getFileInfo().getFileSize() > 0 : "Thumbnail length 0"; assert is.getFileInfo().getMetadata().bytes > 0 : "Original file size 0"; } |
RollingNumber { public double getAvg(CounterDataType counterDataType) { long latestRollingSum = getTotalSum(counterDataType); return (double)(latestRollingSum) / intervals; } RollingNumber(); void addOne(CounterDataType dataType); void add(CounterDataType dataType, long value); long getTotalSum(CounterDataType dataType); double getAvg(CounterDataType counterDataType); } | @Test public void test() { for (int i = 0; i < 10; i++) { new Thread(() -> { while (true) { testMock(); } }).start(); } new Thread(() -> { try { while (true) { Thread.sleep(1000); System.out.println(rollingNumber.getAvg(CounterDataType.PASSED)); } } catch (Exception e) { } }).start(); try { System.in.read(); } catch (Exception e) { } System.out.println("程序退出"); } |
FileUtils { public static List<File> getFileListByPath(String path) { return getFileListByPath(path, null); } static String getExtension(String fileName); static void writeByteArrayToFile(File file, byte[] data, boolean append); static byte[] readFileToByteArray(File file); static void writeStringToFile(File file, String data, String encoding, boolean append); static String readFileToString(File file, String encoding); static String byteCountToDisplaySize(long size); static void moveDirectoryToDirectory(File src, File destDir, boolean isCover); static void moveFileToDirectory(File srcFile, File destDir, boolean isCover); static void moveFile(File srcFile, File destFile, boolean isCover); static void copyDirectoryToDirectory(File srcDir, File destDir); static void copyDirectoryToDirectory(File srcDir, File destDir, FileFilter filter); static void copyFileToDirectory(File srcFile, File destDir); static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate); static void copyFile(File srcFile, File destFile); static void copyFile(File srcFile, File destFile, boolean preserveFileDate); static void deleteFileOrDirectoryQuietly(String filePath); static void deleteFileOrDirectory(String filePath, boolean deleteThisPath); static List<File> getFileListByPath(String path); static List<File> getFileListByPath(String path, FileFilter filter); static Properties readProperties(String path); static Properties readProperties(InputStream in); static void writeProperties(String path, Properties properties); static final String EMPTY; static final long ONE_KB; static final long ONE_MB; static final long ONE_GB; static final long ONE_TB; static final long ONE_PB; static final long ONE_EB; } | @Test public void testGetFileListByPath() { List<File> fileList = FileUtils.getFileListByPath("/Users/xuan/Desktop/xuan"); for (File f : fileList) { System.out.println(f.getName()); } } |
Validators { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } static boolean isAlphanumeric(String str); static boolean isBlank(String str); static boolean isDate(String str); static boolean isDateTime(String str); static boolean isEmail(String str); static boolean isEmpty(Object[] args); static boolean isEmpty(String str); static boolean isEmpty(Collection<T> collection); static boolean isEmptyMap(Map<K, V> map); static boolean isIdCardNumber(String str); static boolean isNumber(String str); static boolean isNumber(String str, int min, int max); static boolean isNumeric(String str); static boolean isNumeric(String str, int fractionNum); static boolean isPostcode(String str); static boolean isString(String str, int minLength, int maxLength); static boolean isTime(String str); static boolean isSimpleChinese(String str); static boolean isRegexMatch(String str, String regex); } | @Test public void testIsBlank(){ Assert.assertTrue(Validators.isBlank(null)); Assert.assertTrue(Validators.isBlank("")); Assert.assertTrue(Validators.isBlank(" ")); Assert.assertTrue(!Validators.isBlank("bob")); Assert.assertTrue(!Validators.isBlank(" bob ")); } |
MathUtils { public static double add(double v1, double v2) { BigDecimal b1 = createBigDecimal(v1); BigDecimal b2 = createBigDecimal(v2); return b1.add(b2).doubleValue(); } static double add(double v1, double v2); static double div(double v1, double v2); static double div(double v1, double v2, int scale); static boolean isInvalidDouble(double v); static double mul(double v1, double v2); static double round(double v, int scale); static double sub(double v1, double v2); } | @Test public void testAdd() { System.out.println(MathUtils.add(1.1d, 1.2d)); } |
Diverter { public boolean isHit(long bizId) { return hitNum(bizId) >= 0; } Diverter(DiverterConfig config); boolean isHit(long bizId); long hitNum(long bizId); } | @Test public void test() { for (long i = 0; i < 100; i++) { boolean hit = diverter.isHit(i); System.out.println("i=" + i + ".hit=" + hit); } } |
UUIDUtils { public static String uuid() { return uuid.generateHex(); } private UUIDUtils(); byte[] generateBytes(); static String uuid(); } | @Test public void testUuid() { Set<String> idSet = new HashSet<>(); for (int i = 0; i < 50; i++) { new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < 30000; i++) { String uuid = UUIDUtils.uuid(); if (idSet.contains(uuid)) { System.out.println("++++++++++uuid重复:" + uuid); } } } }).start(); } } |
LocalKvUtils { public static String get(String path, String key) { Properties properties = getPropertiesFromPath(path); if (null == properties) { return null; } return properties.getProperty(key); } static void put(String path, String key, String value); static void put(String path, Map<String, String> map); static String get(String path, String key); static void remove(String path, String key); static void removeAll(String path); static void writeProperties(String path, Properties properties); } | @Test public void testGet() { String install = LocalKvUtils.get(path, "install"); System.out.println("==========>" + install); } |
LocalKvUtils { public static void put(String path, String key, String value) { Properties properties = getPropertiesFromPath(path); if (null == properties) { return; } properties.put(key, value); writeProperties(path, properties); } static void put(String path, String key, String value); static void put(String path, Map<String, String> map); static String get(String path, String key); static void remove(String path, String key); static void removeAll(String path); static void writeProperties(String path, Properties properties); } | @Test public void testPut() { LocalKvUtils.put(path, "install", "2"); LocalKvUtils.put(path, "test", "200"); } |
LocalKvUtils { public static void remove(String path, String key) { Properties properties = getPropertiesFromPath(path); if (null == properties) { return; } properties.remove(key); writeProperties(path, properties); } static void put(String path, String key, String value); static void put(String path, Map<String, String> map); static String get(String path, String key); static void remove(String path, String key); static void removeAll(String path); static void writeProperties(String path, Properties properties); } | @Test public void testRemove() { LocalKvUtils.remove(path, "test"); } |
LocalKvUtils { public static void removeAll(String path) { if (null == path) { return; } File file = new File(path); if (file.exists()) { file.delete(); } } static void put(String path, String key, String value); static void put(String path, Map<String, String> map); static String get(String path, String key); static void remove(String path, String key); static void removeAll(String path); static void writeProperties(String path, Properties properties); } | @Test public void testRemoveAll() { LocalKvUtils.removeAll(path); } |
Map2BeanUtils { public static <T> T map2Bean(Map<String, Object> map, Class<T> beanClass) { T obj; try { obj = beanClass.newInstance(); BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String key = property.getName(); if (!map.containsKey(key)) { continue; } Object value = map.get(key); Method setter = property.getWriteMethod(); setter.invoke(obj, value); } } catch (Exception e) { throw new RuntimeException(e); } return obj; } static T map2Bean(Map<String, Object> map, Class<T> beanClass); static Map<String, Object> bean2Map(Object obj); } | @Test public void testMap2Bean() { Map<String, Object> map = new HashMap<>(); map.put("name", "xuan"); map.put("age", 18); map.put("sonName", "xuanson"); Son user = Map2BeanUtils.map2Bean(map, Son.class); System.out.println("++++++++++user:" + user.getName() + "---" + user.getAge() + "---" + user.getSonName()); } |
Map2BeanUtils { public static Map<String, Object> bean2Map(Object obj) { if (obj == null) { return null; } Map<String, Object> map = new HashMap<>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String key = property.getName(); if (key.equals("class")) { continue; } Method getter = property.getReadMethod(); Object value = getter.invoke(obj); map.put(key, value); } } catch (Exception e) { throw new RuntimeException(e); } return map; } static T map2Bean(Map<String, Object> map, Class<T> beanClass); static Map<String, Object> bean2Map(Object obj); } | @Test public void testBean2Map(){ Son user = new Son(); user.setName("xuan"); user.setAge(20); user.setSonName("xuanson"); Map map = Map2BeanUtils.bean2Map(user); System.out.println("++++++++++map:" + map); }
@Test public void testBean2Map2(){ Son son = new Son(); son.setSonName("sonName"); son.setAge(20); son.setName("name"); Son2 son2 = new Son2(); son2.setSon2Name("son2Name"); son2.setAge(22); son2.setName("name2"); Father father = new Father(); father.setAge(88); father.setName("name3"); Family family = new Family(); family.setSon(son); family.setSon2(son2); family.setFather(father); Map map = Map2BeanUtils.bean2Map(family); System.out.println("++++++++++map:" + map); } |
JavaCommOpenHandler extends CommOpenHandler { public Handler<Message>[] getKernelControlChanelHandlers(String targetName){ if(TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)){ return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS; }else{ return (Handler<Message>[]) new Handler<?>[0]; } } JavaCommOpenHandler(KernelFunctionality kernel); Handler<Message>[] getKernelControlChanelHandlers(String targetName); } | @Test public void getControlHandlersWithEmptyString_returnEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(""); Assertions.assertThat(handlers).isEmpty(); }
@Test public void getControlHandlersWithTargetName_returnNotEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(targetName); Assertions.assertThat(handlers).isNotEmpty(); } |
ValueWidget extends DOMWidget { public Boolean getBoolean(Object input) { Boolean ret = false; if (input != null) { if (input instanceof Boolean) { ret = (Boolean) input; } else if (input instanceof String) { ret = new Boolean((String) input); } } return ret; } T getValue(); void setValue(Object value); @Override void updateValue(Object input); abstract T getValueFromObject(Object input); Boolean getDisabled(); void setDisabled(Object disabled); Boolean getVisible(); void setVisible(Object visible); String getDescription(); void setDescription(Object description); Integer getMsg_throttle(); void setMsg_throttle(Object msg_throttle); Integer getInteger(Object input); Double getDouble(Object input); String getString(Object input); String[] getStringArray(Object input); Boolean getBoolean(Object input); } | @Test public void getBooleanWithBooleanParam_returnBoolean() throws Exception { Boolean value = valueWidget.getBoolean(Boolean.TRUE); Assertions.assertThat(value).isTrue(); }
@Test public void getBooleanWithStringParam_returnBoolean() throws Exception { Boolean value = valueWidget.getBoolean("true"); Assertions.assertThat(value).isTrue(); }
@Test public void getBooleanWithNullParam_returnFalse() throws Exception { Boolean value = valueWidget.getBoolean(null); Assertions.assertThat(value).isFalse(); } |
Comm { public void open() { Message parentMessage = getParentMessage(); Message message = new Message(); message.setHeader(new Header(COMM_OPEN, parentMessage != null ? parentMessage.getHeader().getSession() : null)); if (parentMessage != null) { message.setParentHeader(getParentMessage().getHeader()); } HashMap<String, Serializable> map = new HashMap<>(); map.put(COMM_ID, getCommId()); map.put(TARGET_NAME, getTargetName()); map.put(DATA, data); map.put(TARGET_MODULE, getTargetModule()); message.setContent(map); kernel.publish(message); kernel.addComm(getCommId(), this); } Comm(String commId, String targetName); Comm(String commId, TargetNamesEnum targetName); Comm(TargetNamesEnum targetName); Comm(String targetName); String getCommId(); String getTargetName(); HashMap<?, ?> getData(); void setData(HashMap<?, ?> data); String getTargetModule(); void setTargetModule(String targetModule); List<Handler<Message>> getMsgCallbackList(); void addMsgCallbackList(Handler<Message>... handlers); void clearMsgCallbackList(); List<Handler<Message>> getCloseCallbackList(); void addCloseCallbackList(Handler<Message>... handlers); void clearCloseCallbackList(); void open(); void close(); void send(); void sendUpdate(final String propertyName, final Object value); void handleMsg(Message parentMessage); @Override String toString(); static final String METHOD; static final String UPDATE; static final String STATE; static final String COMM_ID; static final String TARGET_NAME; static final String DATA; static final String TARGET_MODULE; static final String COMMS; } | @Test public void commOpen_shouldSendIOPubSocketMessage() throws NoSuchAlgorithmException { comm.open(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Assertions.assertThat(kernel.getPublishedMessages().get(0)).isNotNull(); }
@Test public void commOpen_sentMessageHasTypeIsCommOpen() throws NoSuchAlgorithmException { comm.open(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_OPEN.getName()); }
@Test public void commOpen_sentMessageHasCommId() throws NoSuchAlgorithmException { comm.open(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat((String) sendMessage.getContent().get(Comm.COMM_ID)).isNotEmpty(); }
@Test public void commOpen_sentMessageHasTargetName() throws NoSuchAlgorithmException { comm.open(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat((String) sendMessage.getContent().get(Comm.TARGET_NAME)).isNotEmpty(); }
@Test public void commOpen_sentMessageHasData() throws NoSuchAlgorithmException { initCommData(comm); comm.open(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat((Map) sendMessage.getContent().get(Comm.DATA)).isNotEmpty(); } |
Comm { public void close() { Message parentMessage = getParentMessage(); if (this.getCloseCallbackList() != null && !this.getCloseCallbackList().isEmpty()) { for (Handler<Message> handler : getCloseCallbackList()) { handler.handle(parentMessage); } } Message message = new Message(); message.setHeader(new Header(COMM_CLOSE, parentMessage != null ? parentMessage.getHeader().getSession() : null)); if (parentMessage != null) { message.setParentHeader(parentMessage.getHeader()); } HashMap<String, Serializable> map = new HashMap<>(); map.put(COMM_ID, getCommId()); map.put(DATA, new HashMap<>()); message.setContent(map); kernel.removeComm(getCommId()); kernel.publish(message); } Comm(String commId, String targetName); Comm(String commId, TargetNamesEnum targetName); Comm(TargetNamesEnum targetName); Comm(String targetName); String getCommId(); String getTargetName(); HashMap<?, ?> getData(); void setData(HashMap<?, ?> data); String getTargetModule(); void setTargetModule(String targetModule); List<Handler<Message>> getMsgCallbackList(); void addMsgCallbackList(Handler<Message>... handlers); void clearMsgCallbackList(); List<Handler<Message>> getCloseCallbackList(); void addCloseCallbackList(Handler<Message>... handlers); void clearCloseCallbackList(); void open(); void close(); void send(); void sendUpdate(final String propertyName, final Object value); void handleMsg(Message parentMessage); @Override String toString(); static final String METHOD; static final String UPDATE; static final String STATE; static final String COMM_ID; static final String TARGET_NAME; static final String DATA; static final String TARGET_MODULE; static final String COMMS; } | @Test public void commClose_shouldSendIOPubSocketMessage() throws NoSuchAlgorithmException { comm.close(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Assertions.assertThat(kernel.getPublishedMessages().get(0)).isNotNull(); }
@Test public void commClose_sentMessageHasTypeIsCommClose() throws NoSuchAlgorithmException { comm.close(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_CLOSE.getName()); }
@Test public void commClose_sentMessageHasEmptyData() throws NoSuchAlgorithmException { initCommData(comm); comm.close(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat((Map) sendMessage.getContent().get(Comm.DATA)).isEmpty(); } |
ScalaCommOpenHandler extends CommOpenHandler { public Handler<Message>[] getKernelControlChanelHandlers(String targetName){ if(TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)){ return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS; }else{ return (Handler<Message>[]) new Handler<?>[0]; } } ScalaCommOpenHandler(KernelFunctionality kernel); Handler<Message>[] getKernelControlChanelHandlers(String targetName); } | @Test public void getControlHandlersWithTargetName_returnNotEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(targetName); Assertions.assertThat(handlers).isNotEmpty(); }
@Test public void getControlHandlersWithEmptyString_returnEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(""); Assertions.assertThat(handlers).isEmpty(); } |
Comm { public void send() { Message parentMessage = getParentMessage(); Message message = new Message(); message.setHeader(new Header(COMM_MSG, parentMessage != null ? parentMessage.getHeader().getSession() : null)); if (parentMessage != null) { message.setParentHeader(getParentMessage().getHeader()); } HashMap<String, Serializable> map = new HashMap<>(6); map.put(COMM_ID, getCommId()); map.put(DATA, data); message.setContent(map); kernel.publish(message); } Comm(String commId, String targetName); Comm(String commId, TargetNamesEnum targetName); Comm(TargetNamesEnum targetName); Comm(String targetName); String getCommId(); String getTargetName(); HashMap<?, ?> getData(); void setData(HashMap<?, ?> data); String getTargetModule(); void setTargetModule(String targetModule); List<Handler<Message>> getMsgCallbackList(); void addMsgCallbackList(Handler<Message>... handlers); void clearMsgCallbackList(); List<Handler<Message>> getCloseCallbackList(); void addCloseCallbackList(Handler<Message>... handlers); void clearCloseCallbackList(); void open(); void close(); void send(); void sendUpdate(final String propertyName, final Object value); void handleMsg(Message parentMessage); @Override String toString(); static final String METHOD; static final String UPDATE; static final String STATE; static final String COMM_ID; static final String TARGET_NAME; static final String DATA; static final String TARGET_MODULE; static final String COMMS; } | @Test public void commSend_shouldSendIOPubSocketMessage() throws NoSuchAlgorithmException { comm.send(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Assertions.assertThat(kernel.getPublishedMessages().get(0)).isNotNull(); }
@Test public void commSend_sentMessageHasTypeIsCommClose() throws NoSuchAlgorithmException { comm.send(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_MSG.getName()); }
@Test public void commSend_sentMessageHasCommId() throws NoSuchAlgorithmException { comm.send(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat((String) sendMessage.getContent().get(Comm.COMM_ID)).isNotEmpty(); }
@Test public void commClose_sentMessageHasData() throws NoSuchAlgorithmException { initCommData(comm); comm.send(); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message sendMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat((Map) sendMessage.getContent().get(Comm.DATA)).isNotEmpty(); } |
CommMsgHandler extends KernelHandler<Message> { public void handle(Message message) { wrapBusyIdle(kernel, message, () -> { handleMsg(message); }); } CommMsgHandler(final KernelFunctionality kernel, final MessageCreator messageCreator); void handle(Message message); static String getString(Map<String, Serializable> map, String name); } | @Test public void handleMessage_shouldSendTwoMessages() throws Exception { commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Assertions.assertThat(kernel.getPublishedMessages().size()).isEqualTo(2); }
@Test public void handleMessage_firstSentMessageHasExecutionStateIsBusy() throws Exception { commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getContent().get("execution_state")).isEqualTo("busy"); }
@Test public void handleMessage_firstSentMessageHasSessionId() throws Exception { String expectedSessionId = message.getHeader().getSession(); commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void handleMessage_firstSentMessageHasTypeIsStatus() throws Exception { commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getHeader().getType()) .isEqualTo(JupyterMessages.STATUS.getName()); }
@Test public void handleMessage_firstSentMessageHasParentHeader() throws Exception { String expectedHeader = message.getHeader().asJson(); commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getParentHeader().asJson()).isEqualTo(expectedHeader); }
@Test public void handleMessage_firstSentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(new String(publishMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); }
@Test public void handleMessage_secondSentMessageHasExecutionStateIsIdle() throws Exception { commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getContent().get("execution_state")).isEqualTo("idle"); }
@Test public void handleMessage_secondSentMessageHasSessionId() throws Exception { String expectedSessionId = message.getHeader().getSession(); commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void handleMessage_secondSendMessageHasTypeIsStatus() throws Exception { commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getHeader().getType()) .isEqualTo(JupyterMessages.STATUS.getName()); }
@Test public void handleMessage_secondSentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); commMsgHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(new String(publishMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); } |
ScalaKernelInfoHandler extends KernelHandler<Message> { @Override public void handle(Message message) { logger.debug("Processing kernel info request"); Message reply = new Message(); HashMap<String, Serializable> map = new HashMap<>(6); map.put("protocol_version", "5.0"); map.put("implementation", "scala"); map.put("implementation_version", "1.0.0"); HashMap<String, Serializable> map1 = new HashMap<String, Serializable>(7); map1.put("name", "Scala"); map1.put("version", scala.util.Properties.scalaPropOrElse("version.number", "(unknown)")); map1.put("mimetype", ""); map1.put("file_extension", ".scala"); map1.put("codemirror_mode", "text/x-scala"); map1.put("nbconverter_exporter", ""); map.put("language_info", map1); map.put("banner", "BeakerX kernel for Scala"); map.put("beakerx", true); map.put("help_links", new ArrayList<String>()); reply.setContent(map); reply.setHeader(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); send(reply); } ScalaKernelInfoHandler(KernelFunctionality kernel); @Override void handle(Message message); } | @Test public void handle_shouldSendMessage() throws Exception { handler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); }
@Test public void handle_sentMessageHasContent() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sentMessage.getContent()).isNotEmpty(); }
@Test public void handle_sentMessageHasHeaderTypeIsKernelInfoReply() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Header header = sentMessage.getHeader(); Assertions.assertThat(header).isNotNull(); Assertions.assertThat(header.getType()).isEqualTo(KERNEL_INFO_REPLY.getName()); }
@Test public void handle_sentMessageHasLanguageInfo() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("language_info")).isNotNull(); }
@Test public void handle_messageContentHasScalaLabel() throws Exception { handler.handle(message); Message sentMessage = kernel.getSentMessages().get(0); Map<String, Serializable> map = sentMessage.getContent(); Assertions.assertThat(map).isNotNull(); Assertions.assertThat(map.get("implementation")).isEqualTo("scala"); } |
ExecuteRequestHandler extends KernelHandler<Message> { @Override public void handle(Message message) { try { handleMsg(message); } catch (InterruptedException e) { throw new RuntimeException(e); } } ExecuteRequestHandler(KernelFunctionality kernel); @Override void handle(Message message); @Override void exit(); } | @Test public void handleMessage_shouldSendTwoMessages() throws Exception { executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Assertions.assertThat(kernel.getPublishedMessages().size()).isEqualTo(2); }
@Test public void handleMessage_firstSentMessageHasExecutionStateIsBusy() throws Exception { executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getContent().get("execution_state")).isEqualTo("busy"); }
@Test public void handleMessage_firstSentMessageHasSessionId() throws Exception { String expectedSessionId = message.getHeader().getSession(); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void handleMessage_firstSentMessageHasTypeIsStatus() throws Exception { executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getHeader().getType()) .isEqualTo(JupyterMessages.STATUS.getName()); }
@Test public void handleMessage_firstSentMessageHasParentHeader() throws Exception { String expectedHeader = message.getHeader().asJson(); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(publishMessage.getParentHeader().asJson()).isEqualTo(expectedHeader); }
@Test public void handleMessage_firstSentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(0); Assertions.assertThat(new String(publishMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); }
@Test public void handleMessage_secondSentMessageHasSessionId() throws Exception { String expectedSessionId = message.getHeader().getSession(); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void handleMessage_secondSendMessageHasTypeIsExecutionInput() throws Exception { executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getHeader().getType()) .isEqualTo(JupyterMessages.EXECUTE_INPUT.getName()); }
@Test public void handleMessage_secondSentMessageHasContentCode() throws Exception { String expectedCode = (String) message.getContent().get("code"); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getContent().get("code")).isEqualTo(expectedCode); }
@Test public void handleMessage_secondSentMessageHasContentExecutionCount() throws Exception { executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getContent().get("execution_count")).isNotNull(); }
@Test public void handleMessage_secondSentMessageHasParentHeader() throws Exception { String expectedHeader = message.getHeader().asJson(); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(publishMessage.getParentHeader().asJson()).isEqualTo(expectedHeader); }
@Test public void handleMessage_secondSentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); executeRequestHandler.handle(message); Assertions.assertThat(kernel.getPublishedMessages()).isNotEmpty(); Message publishMessage = kernel.getPublishedMessages().get(1); Assertions.assertThat(new String(publishMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); } |
CommCloseHandler extends KernelHandler<Message> { @Override public void handle(Message message) { wrapBusyIdle(kernel, message, () -> { handleMsg(message); }); } CommCloseHandler(KernelFunctionality kernel); static String getString(Map<String, Serializable> map, String name); @Override void handle(Message message); } | @Test public void handleMessage_shouldSendShellSocketMessage() throws Exception { commCloseHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); }
@Test public void handleMessage_sentMessageHasTypeIsCommClose() throws Exception { commCloseHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_CLOSE.getName()); }
@Test public void handleMessage_sentMessageHasSessionId() throws Exception { String expectedSessionId = message.getHeader().getSession(); commCloseHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void handleMessage_sentMessageHasParentHeader() throws Exception { String expectedHeader = message.getHeader().asJson(); commCloseHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getParentHeader().asJson()).isEqualTo(expectedHeader); }
@Test public void handleMessage_sentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); commCloseHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(new String(sendMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); } |
CommInfoHandler extends KernelHandler<Message> { @Override public void handle(Message message) { wrapBusyIdle(kernel, message, () -> { handleMsg(message); }); } CommInfoHandler(KernelFunctionality kernel); @Override void handle(Message message); } | @Test public void handleMessage_shouldSendShellSocketMessage() throws Exception { commInfoHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); }
@Test public void handleMessage_sentMessageHasTypeIsCommInfoReply() throws Exception { commInfoHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_INFO_REPLY.getName()); }
@Test public void handleMessage_sentMessageHasSessionId() throws Exception { String expectedSessionId = message.getHeader().getSession(); commInfoHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getSession()).isEqualTo(expectedSessionId); }
@Test public void handleMessage_sentMessageHasParentHeader() throws Exception { String expectedHeader = message.getHeader().asJson(); commInfoHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getParentHeader().asJson()).isEqualTo(expectedHeader); }
@Test public void handleMessage_sentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); commInfoHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(new String(sendMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); } |
CommOpenHandler extends KernelHandler<Message> { @Override public void handle(Message message) { wrapBusyIdle(kernel, message, () -> { handleMsg(message); }); } CommOpenHandler(KernelFunctionality kernel); @Override void handle(Message message); abstract Handler<Message>[] getKernelControlChanelHandlers(String targetName); static String getString(Map<String, Serializable> map, String name); } | @Test public void handleMessage_shouldSendShellSocketMessage() throws Exception { commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); }
@Test public void handleMessageWithoutCommId_shouldSendCloseCommMessage() throws Exception { message.getContent().remove(COMM_ID); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_CLOSE.getName()); }
@Test public void handleMessageWithoutTargetName_shouldSendCloseCommMessage() throws Exception { message.getContent().remove(TARGET_NAME); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getHeader().getType()) .isEqualTo(JupyterMessages.COMM_CLOSE.getName()); }
@Test public void handleMessage_sentMessageHasCommId() throws Exception { String expectedCommId = (String) message.getContent().get(COMM_ID); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getContent().get(COMM_ID)).isEqualTo(expectedCommId); }
@Test public void handleMessage_sentMessageHasTargetName() throws Exception { String expectedTargetName = (String) message.getContent().get(TARGET_NAME); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getContent().get(TARGET_NAME)).isEqualTo(expectedTargetName); }
@Test public void handleMessage_sentMessageHasEmptyData() throws Exception { commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat((Map) sendMessage.getContent().get(DATA)).isEmpty(); }
@Test public void handleMessage_sentMessageHasTargetModule() throws Exception { String expectedTargetModule = (String) message.getContent().get(TARGET_MODULE); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getContent().get(TARGET_MODULE)) .isEqualTo(expectedTargetModule); }
@Test public void handleMessage_sentMessageHasParentHeader() throws Exception { String expectedHeader = message.getHeader().asJson(); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(sendMessage.getParentHeader().asJson()).isEqualTo(expectedHeader); }
@Test public void handleMessage_sentMessageHasIdentities() throws Exception { String expectedIdentities = new String(message.getIdentities().get(0)); commOpenHandler.handle(message); Assertions.assertThat(kernel.getSentMessages()).isNotEmpty(); Message sendMessage = kernel.getSentMessages().get(0); Assertions.assertThat(new String(sendMessage.getIdentities().get(0))) .isEqualTo(expectedIdentities); } |
MessageCreator { public synchronized List<MessageHolder> createMessage(SimpleEvaluationObject seo) { logger.debug("Creating message response message from: " + seo); Message message = seo.getJupyterMessage(); List<MessageHolder> ret = new ArrayList<>(); if (isConsoleOutputMessage(seo)) { ret.addAll(createConsoleResult(seo, message)); } else if (isSupportedStatus(seo.getStatus())) { ret.addAll(createResultForSupportedStatus(seo, message)); } else { logger.debug("Unhandled status of SimpleEvaluationObject : " + seo.getStatus()); } return ret; } MessageCreator(KernelFunctionality kernel); Message buildMessage(Message message, String mime, String code, int executionCount); Message buildClearOutput(Message message, boolean wait); Message buildDisplayData(Message message, MIMEContainer value); Message buildOutputMessage(Message message, String text, boolean hasError); synchronized void createMagicMessage(Message reply, int executionCount, Message message); synchronized List<MessageHolder> createMessage(SimpleEvaluationObject seo); Message createBusyMessage(Message parentMessage); Message createIdleMessage(Message parentMessage); static final String EXECUTION_STATE; static final String BUSY; static final String IDLE; static final String TEXT_PLAIN; static final String NULL_RESULT; static Logger logger; } | @Test public void createMessageWithNullResult_shouldReturnNullStringForNull() throws Exception { seo.finished(null); List<MessageHolder> message = messageCreator.createMessage(seo); Map data = TestWidgetUtils.getData(message.get(0).getMessage()); assertThat(data.get(MessageCreator.TEXT_PLAIN)).isEqualTo(NULL_RESULT); }
@Test public void createMessageWithNotNullResult_shouldReturnResult() throws Exception { seo.finished("NotNullResult"); List<MessageHolder> message = messageCreator.createMessage(seo); Map data = TestWidgetUtils.getData(message.get(0).getMessage()); assertThat(data.get(MessageCreator.TEXT_PLAIN)).isEqualTo("NotNullResult"); }
@Test public void createMessageWithNotNullResult_createTwoMessages() throws Exception { seo.finished("result"); List<MessageHolder> messages = messageCreator.createMessage(seo); assertThat(messages).isNotEmpty(); assertThat(messages.size()).isEqualTo(2); }
@Test public void createMessageWithNotNullResult_firstIOPubMessageHasTypeIsExecuteResult() throws Exception { seo.finished("result"); List<MessageHolder> messages = messageCreator.createMessage(seo); assertThat(messages).isNotEmpty(); assertThat(messages.get(0).getSocketType()).isEqualTo(SocketEnum.IOPUB_SOCKET); assertThat(messages.get(0).getMessage().type()).isEqualTo(JupyterMessages.EXECUTE_RESULT); }
@Test public void createMessageWithNotNullResult_secondShellMessageHasTypeIsExecuteReply() throws Exception { seo.finished("result"); List<MessageHolder> messages = messageCreator.createMessage(seo); assertThat(messages).isNotEmpty(); assertThat(messages.get(1).getSocketType()).isEqualTo(SocketEnum.SHELL_SOCKET); assertThat(messages.get(1).getMessage().type()).isEqualTo(JupyterMessages.EXECUTE_REPLY); }
@Test public void createMessageWithError_createTwoMessages() throws Exception { seo.error("some error"); List<MessageHolder> messages = messageCreator.createMessage(seo); assertThat(messages).isNotEmpty(); assertThat(messages.size()).isEqualTo(2); }
@Test public void createMessageWithError_firstIOPubMessageHasTypeIsStream() throws Exception { seo.error("some error"); List<MessageHolder> messages = messageCreator.createMessage(seo); assertThat(messages).isNotEmpty(); assertThat(messages.get(0).getSocketType()).isEqualTo(SocketEnum.IOPUB_SOCKET); assertThat(messages.get(0).getMessage().type()).isEqualTo(JupyterMessages.ERROR); }
@Test public void createMessageWithError_secondShellMessageHasTypeIsExecuteReply() throws Exception { seo.error("some error"); List<MessageHolder> messages = messageCreator.createMessage(seo); assertThat(messages).isNotEmpty(); assertThat(messages.get(1).getSocketType()).isEqualTo(SocketEnum.SHELL_SOCKET); assertThat(messages.get(1).getMessage().type()).isEqualTo(JupyterMessages.EXECUTE_REPLY); } |
MessageCreator { public Message createIdleMessage(Message parentMessage) { return getExecutionStateMessage(parentMessage, IDLE); } MessageCreator(KernelFunctionality kernel); Message buildMessage(Message message, String mime, String code, int executionCount); Message buildClearOutput(Message message, boolean wait); Message buildDisplayData(Message message, MIMEContainer value); Message buildOutputMessage(Message message, String text, boolean hasError); synchronized void createMagicMessage(Message reply, int executionCount, Message message); synchronized List<MessageHolder> createMessage(SimpleEvaluationObject seo); Message createBusyMessage(Message parentMessage); Message createIdleMessage(Message parentMessage); static final String EXECUTION_STATE; static final String BUSY; static final String IDLE; static final String TEXT_PLAIN; static final String NULL_RESULT; static Logger logger; } | @Test public void createIdleMessage_messageHasTypeIsStatus() { Message message = messageCreator.createIdleMessage(new Message()); assertThat(message.type()).isEqualTo(JupyterMessages.STATUS); }
@Test public void createIdleMessage_messageHasExecutionStateIsIdle() { Message message = messageCreator.createIdleMessage(new Message()); Map data = message.getContent(); assertThat(data.get(MessageCreator.EXECUTION_STATE)).isEqualTo(MessageCreator.IDLE); } |
MessageCreator { public Message createBusyMessage(Message parentMessage) { return getExecutionStateMessage(parentMessage, BUSY); } MessageCreator(KernelFunctionality kernel); Message buildMessage(Message message, String mime, String code, int executionCount); Message buildClearOutput(Message message, boolean wait); Message buildDisplayData(Message message, MIMEContainer value); Message buildOutputMessage(Message message, String text, boolean hasError); synchronized void createMagicMessage(Message reply, int executionCount, Message message); synchronized List<MessageHolder> createMessage(SimpleEvaluationObject seo); Message createBusyMessage(Message parentMessage); Message createIdleMessage(Message parentMessage); static final String EXECUTION_STATE; static final String BUSY; static final String IDLE; static final String TEXT_PLAIN; static final String NULL_RESULT; static Logger logger; } | @Test public void createBusyMessage_messageHasTypeIsStatus() { Message message = messageCreator.createBusyMessage(new Message()); assertThat(message.type()).isEqualTo(JupyterMessages.STATUS); }
@Test public void createBusyMessage_messageHasExecutionStateIsBusy() { Message message = messageCreator.createBusyMessage(new Message()); Map data = message.getContent(); assertThat(data.get(MessageCreator.EXECUTION_STATE)).isEqualTo(MessageCreator.BUSY); } |
TableDisplay extends ObservableTableDisplay implements InternalCommWidget { @Override public Comm getComm() { return this.comm; } TableDisplay(List<List<?>> v, List<String> co, List<String> cl); TableDisplay(Collection<Map<?,?>> v); TableDisplay(Collection<Map<?,?>> v, BeakerObjectConverter serializer); private TableDisplay(Map<?, ?> v); @Override Comm getComm(); @Override void close(); @Override String getModelNameValue(); @Override String getViewNameValue(); static TableDisplay createTableDisplayForMap(Map<?,?> v); TimeUnit getStringFormatForTimes(); void setStringFormatForTimes(TimeUnit stringFormatForTimes); Map<ColumnType, TableDisplayStringFormat> getStringFormatForType(); void setStringFormatForType(ColumnType type, TableDisplayStringFormat format); Map<String, TableDisplayStringFormat> getStringFormatForColumn(); void setStringFormatForColumn(String column, TableDisplayStringFormat format); void setStringFormatForColumn(String column, Object closure); Map<ColumnType, TableDisplayCellRenderer> getRendererForType(); void setRendererForType(ColumnType type, TableDisplayCellRenderer renderer); Map<String, TableDisplayCellRenderer> getRendererForColumn(); void setRendererForColumn(String column, TableDisplayCellRenderer renderer); Map<ColumnType, TableDisplayAlignmentProvider> getAlignmentForType(); void setAlignmentProviderForType(ColumnType type, TableDisplayAlignmentProvider alignmentProvider); Map<String, TableDisplayAlignmentProvider> getAlignmentForColumn(); void setAlignmentProviderForColumn(String column, TableDisplayAlignmentProvider alignmentProvider); Map<String, Boolean> getColumnsFrozen(); void setColumnFrozen(String column, boolean frozen); Map<String, Boolean> getColumnsFrozenRight(); void setColumnFrozenRight(String column, boolean frozen); Map<String, Boolean> getColumnsVisible(); void setColumnVisible(String column, boolean visible); List<String> getColumnOrder(); List<TableDisplayCellHighlighter> getCellHighlighters(); void addCellHighlighter(TableDisplayCellHighlighter cellHighlighter); void addCellHighlighter(Object closure); void removeAllCellHighlighters(); void setColumnOrder(List<String> columnOrder); void setToolTip(Object closure); List<List<String>> getTooltips(); Integer getDataFontSize(); void setDataFontSize(Integer dataFontSize); Integer getHeaderFontSize(); void setHeaderFontSize(Integer headerFontSize); List<List<Color>> getFontColor(); void setFontColorProvider(Object closure); void setRowFilter(Object closure); void setHeadersVertical(boolean headersVertical); Boolean getHeadersVertical(); void setHasIndex(String hasIndex); String getHasIndex(); void setTimeZone(String timeZone); String getTimeZone(); List<List<?>> getFilteredValues(); static List<Map<String, Object>> getValuesAsRows(List<List<?>> values, List<String> columns); static List<List<?>> getValuesAsMatrix(List<List<?>> values); static Map<String, Object> getValuesAsDictionary(List<List<?>> values); List<Map<String, Object>> getValuesAsRows(); List<List<?>> getValuesAsMatrix(); Map<String, Object> getValuesAsDictionary(); List<List<?>> getValues(); List<String> getColumnNames(); List<String> getTypes(); String getSubtype(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String TABLE_DISPLAY_SUBTYPE; static final String LIST_OF_MAPS_SUBTYPE; static final String MATRIX_SUBTYPE; static final String DICTIONARY_SUBTYPE; } | @Test public void createTableDisplay_hasCommIsNotNull() throws Exception { TableDisplay tableDisplay = new TableDisplay(getListOfMapsData()); Assertions.assertThat(tableDisplay.getComm()).isNotNull(); } |
TableDisplay extends ObservableTableDisplay implements InternalCommWidget { public static List<Map<String, Object>> getValuesAsRows(List<List<?>> values, List<String> columns) { List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>(); if (columns != null && values != null) { for (List<?> value : values) { Map<String, Object> m = new HashMap<String, Object>(); for (int c = 0; c < columns.size(); c++) { if (value.size() > c) m.put(columns.get(c), value.get(c)); } rows.add(m); } } else { throw new IllegalArgumentException("Method 'getValuesAsRows' doesn't supported for this table"); } return rows; } TableDisplay(List<List<?>> v, List<String> co, List<String> cl); TableDisplay(Collection<Map<?,?>> v); TableDisplay(Collection<Map<?,?>> v, BeakerObjectConverter serializer); private TableDisplay(Map<?, ?> v); @Override Comm getComm(); @Override void close(); @Override String getModelNameValue(); @Override String getViewNameValue(); static TableDisplay createTableDisplayForMap(Map<?,?> v); TimeUnit getStringFormatForTimes(); void setStringFormatForTimes(TimeUnit stringFormatForTimes); Map<ColumnType, TableDisplayStringFormat> getStringFormatForType(); void setStringFormatForType(ColumnType type, TableDisplayStringFormat format); Map<String, TableDisplayStringFormat> getStringFormatForColumn(); void setStringFormatForColumn(String column, TableDisplayStringFormat format); void setStringFormatForColumn(String column, Object closure); Map<ColumnType, TableDisplayCellRenderer> getRendererForType(); void setRendererForType(ColumnType type, TableDisplayCellRenderer renderer); Map<String, TableDisplayCellRenderer> getRendererForColumn(); void setRendererForColumn(String column, TableDisplayCellRenderer renderer); Map<ColumnType, TableDisplayAlignmentProvider> getAlignmentForType(); void setAlignmentProviderForType(ColumnType type, TableDisplayAlignmentProvider alignmentProvider); Map<String, TableDisplayAlignmentProvider> getAlignmentForColumn(); void setAlignmentProviderForColumn(String column, TableDisplayAlignmentProvider alignmentProvider); Map<String, Boolean> getColumnsFrozen(); void setColumnFrozen(String column, boolean frozen); Map<String, Boolean> getColumnsFrozenRight(); void setColumnFrozenRight(String column, boolean frozen); Map<String, Boolean> getColumnsVisible(); void setColumnVisible(String column, boolean visible); List<String> getColumnOrder(); List<TableDisplayCellHighlighter> getCellHighlighters(); void addCellHighlighter(TableDisplayCellHighlighter cellHighlighter); void addCellHighlighter(Object closure); void removeAllCellHighlighters(); void setColumnOrder(List<String> columnOrder); void setToolTip(Object closure); List<List<String>> getTooltips(); Integer getDataFontSize(); void setDataFontSize(Integer dataFontSize); Integer getHeaderFontSize(); void setHeaderFontSize(Integer headerFontSize); List<List<Color>> getFontColor(); void setFontColorProvider(Object closure); void setRowFilter(Object closure); void setHeadersVertical(boolean headersVertical); Boolean getHeadersVertical(); void setHasIndex(String hasIndex); String getHasIndex(); void setTimeZone(String timeZone); String getTimeZone(); List<List<?>> getFilteredValues(); static List<Map<String, Object>> getValuesAsRows(List<List<?>> values, List<String> columns); static List<List<?>> getValuesAsMatrix(List<List<?>> values); static Map<String, Object> getValuesAsDictionary(List<List<?>> values); List<Map<String, Object>> getValuesAsRows(); List<List<?>> getValuesAsMatrix(); Map<String, Object> getValuesAsDictionary(); List<List<?>> getValues(); List<String> getColumnNames(); List<String> getTypes(); String getSubtype(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String TABLE_DISPLAY_SUBTYPE; static final String LIST_OF_MAPS_SUBTYPE; static final String MATRIX_SUBTYPE; static final String DICTIONARY_SUBTYPE; } | @Test public void getValuesAsRowsWithoutParams_returnedListOfMapsIsNotEmpty() throws Exception { TableDisplay tableDisplay = new TableDisplay(getListOfMapsData()); List<Map<String, Object>> rows = tableDisplay.getValuesAsRows(); Assertions.assertThat(rows.size()).isEqualTo(2); Assertions.assertThat(rows.get(0).size()).isEqualTo(3); }
@Test public void getValuesAsRowsWithTwoParams_returnedListOfMapsIsNotEmpty() throws Exception { List<Map<String, Object>> rows = TableDisplay.getValuesAsRows(Arrays.asList(getRowData(), getRowData()), getStringList()); Assertions.assertThat(rows.size()).isEqualTo(2); Assertions.assertThat(rows.get(0).size()).isEqualTo(3); } |
ScalaEvaluator implements Evaluator { @Override public void evaluate(SimpleEvaluationObject seo, String code) { jobQueue.add(new jobDescriptor(code,seo)); syncObject.release(); } @Inject ScalaEvaluator(Provider<BeakerObjectConverter> osp); void initialize(String id, String sId); @Override void startWorker(); String getShellId(); void setupAutoTranslation(); void killAllThreads(); void cancelExecution(); void resetEnvironment(); void exit(); @Override void setShellOptions(final KernelParameters kernelParameters); @Override void evaluate(SimpleEvaluationObject seo, String code); @Override AutocompleteResult autocomplete(String code, int caretPosition); } | @Test public void evaluatePlot_shouldCreatePlotObject() throws Exception { String code = "import com.twosigma.beaker.chart.xychart.Plot;\n" + "val plot = new Plot();\n" + "plot.setTitle(\"test title\");"; SimpleEvaluationObject seo = new SimpleEvaluationObject(code, new ExecuteCodeCallbackTest()); scalaEvaluator.evaluate(seo, code); waitForResult(seo); Assertions.assertThat(seo.getStatus()).isEqualTo(FINISHED); Assertions.assertThat(seo.getPayload() instanceof Plot).isTrue(); Assertions.assertThat(((Plot)seo.getPayload()).getTitle()).isEqualTo("test title"); }
@Test public void evaluateDivisionByZero_shouldReturnArithmeticException() throws Exception { String code = "16/0"; SimpleEvaluationObject seo = new SimpleEvaluationObject(code, new ExecuteCodeCallbackTest()); scalaEvaluator.evaluate(seo, code); waitForResult(seo); Assertions.assertThat(seo.getStatus()).isEqualTo(ERROR); Assertions.assertThat((String)seo.getPayload()).contains("java.lang.ArithmeticException"); } |
TableDisplay extends ObservableTableDisplay implements InternalCommWidget { public static List<List<?>> getValuesAsMatrix(List<List<?>> values) { return values; } TableDisplay(List<List<?>> v, List<String> co, List<String> cl); TableDisplay(Collection<Map<?,?>> v); TableDisplay(Collection<Map<?,?>> v, BeakerObjectConverter serializer); private TableDisplay(Map<?, ?> v); @Override Comm getComm(); @Override void close(); @Override String getModelNameValue(); @Override String getViewNameValue(); static TableDisplay createTableDisplayForMap(Map<?,?> v); TimeUnit getStringFormatForTimes(); void setStringFormatForTimes(TimeUnit stringFormatForTimes); Map<ColumnType, TableDisplayStringFormat> getStringFormatForType(); void setStringFormatForType(ColumnType type, TableDisplayStringFormat format); Map<String, TableDisplayStringFormat> getStringFormatForColumn(); void setStringFormatForColumn(String column, TableDisplayStringFormat format); void setStringFormatForColumn(String column, Object closure); Map<ColumnType, TableDisplayCellRenderer> getRendererForType(); void setRendererForType(ColumnType type, TableDisplayCellRenderer renderer); Map<String, TableDisplayCellRenderer> getRendererForColumn(); void setRendererForColumn(String column, TableDisplayCellRenderer renderer); Map<ColumnType, TableDisplayAlignmentProvider> getAlignmentForType(); void setAlignmentProviderForType(ColumnType type, TableDisplayAlignmentProvider alignmentProvider); Map<String, TableDisplayAlignmentProvider> getAlignmentForColumn(); void setAlignmentProviderForColumn(String column, TableDisplayAlignmentProvider alignmentProvider); Map<String, Boolean> getColumnsFrozen(); void setColumnFrozen(String column, boolean frozen); Map<String, Boolean> getColumnsFrozenRight(); void setColumnFrozenRight(String column, boolean frozen); Map<String, Boolean> getColumnsVisible(); void setColumnVisible(String column, boolean visible); List<String> getColumnOrder(); List<TableDisplayCellHighlighter> getCellHighlighters(); void addCellHighlighter(TableDisplayCellHighlighter cellHighlighter); void addCellHighlighter(Object closure); void removeAllCellHighlighters(); void setColumnOrder(List<String> columnOrder); void setToolTip(Object closure); List<List<String>> getTooltips(); Integer getDataFontSize(); void setDataFontSize(Integer dataFontSize); Integer getHeaderFontSize(); void setHeaderFontSize(Integer headerFontSize); List<List<Color>> getFontColor(); void setFontColorProvider(Object closure); void setRowFilter(Object closure); void setHeadersVertical(boolean headersVertical); Boolean getHeadersVertical(); void setHasIndex(String hasIndex); String getHasIndex(); void setTimeZone(String timeZone); String getTimeZone(); List<List<?>> getFilteredValues(); static List<Map<String, Object>> getValuesAsRows(List<List<?>> values, List<String> columns); static List<List<?>> getValuesAsMatrix(List<List<?>> values); static Map<String, Object> getValuesAsDictionary(List<List<?>> values); List<Map<String, Object>> getValuesAsRows(); List<List<?>> getValuesAsMatrix(); Map<String, Object> getValuesAsDictionary(); List<List<?>> getValues(); List<String> getColumnNames(); List<String> getTypes(); String getSubtype(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String TABLE_DISPLAY_SUBTYPE; static final String LIST_OF_MAPS_SUBTYPE; static final String MATRIX_SUBTYPE; static final String DICTIONARY_SUBTYPE; } | @Test public void getValuesAsMatrixWithoutParams_returnedListOfListIsNotEmpty() throws Exception { TableDisplay tableDisplay = new TableDisplay(getListOfMapsData()); List<List<?>> values = tableDisplay.getValuesAsMatrix(); Assertions.assertThat(values).isNotEmpty(); }
@Test public void getValuesAsMatrixWithParam_returnedListOfListIsNotEmpty() throws Exception { List<List<?>> values = TableDisplay.getValuesAsMatrix(Arrays.asList(getStringList(), getRowData())); Assertions.assertThat(values).isNotEmpty(); } |
TableDisplay extends ObservableTableDisplay implements InternalCommWidget { public static Map<String, Object> getValuesAsDictionary(List<List<?>> values) { Map<String, Object> m = new HashMap<String, Object>(); for (List<?> l : values) { if (l.size() != 2) throw new IllegalArgumentException("Method 'getValuesAsDictionary' doesn't supported for this table"); ; m.put(l.get(0).toString(), l.get(1)); } return m; } TableDisplay(List<List<?>> v, List<String> co, List<String> cl); TableDisplay(Collection<Map<?,?>> v); TableDisplay(Collection<Map<?,?>> v, BeakerObjectConverter serializer); private TableDisplay(Map<?, ?> v); @Override Comm getComm(); @Override void close(); @Override String getModelNameValue(); @Override String getViewNameValue(); static TableDisplay createTableDisplayForMap(Map<?,?> v); TimeUnit getStringFormatForTimes(); void setStringFormatForTimes(TimeUnit stringFormatForTimes); Map<ColumnType, TableDisplayStringFormat> getStringFormatForType(); void setStringFormatForType(ColumnType type, TableDisplayStringFormat format); Map<String, TableDisplayStringFormat> getStringFormatForColumn(); void setStringFormatForColumn(String column, TableDisplayStringFormat format); void setStringFormatForColumn(String column, Object closure); Map<ColumnType, TableDisplayCellRenderer> getRendererForType(); void setRendererForType(ColumnType type, TableDisplayCellRenderer renderer); Map<String, TableDisplayCellRenderer> getRendererForColumn(); void setRendererForColumn(String column, TableDisplayCellRenderer renderer); Map<ColumnType, TableDisplayAlignmentProvider> getAlignmentForType(); void setAlignmentProviderForType(ColumnType type, TableDisplayAlignmentProvider alignmentProvider); Map<String, TableDisplayAlignmentProvider> getAlignmentForColumn(); void setAlignmentProviderForColumn(String column, TableDisplayAlignmentProvider alignmentProvider); Map<String, Boolean> getColumnsFrozen(); void setColumnFrozen(String column, boolean frozen); Map<String, Boolean> getColumnsFrozenRight(); void setColumnFrozenRight(String column, boolean frozen); Map<String, Boolean> getColumnsVisible(); void setColumnVisible(String column, boolean visible); List<String> getColumnOrder(); List<TableDisplayCellHighlighter> getCellHighlighters(); void addCellHighlighter(TableDisplayCellHighlighter cellHighlighter); void addCellHighlighter(Object closure); void removeAllCellHighlighters(); void setColumnOrder(List<String> columnOrder); void setToolTip(Object closure); List<List<String>> getTooltips(); Integer getDataFontSize(); void setDataFontSize(Integer dataFontSize); Integer getHeaderFontSize(); void setHeaderFontSize(Integer headerFontSize); List<List<Color>> getFontColor(); void setFontColorProvider(Object closure); void setRowFilter(Object closure); void setHeadersVertical(boolean headersVertical); Boolean getHeadersVertical(); void setHasIndex(String hasIndex); String getHasIndex(); void setTimeZone(String timeZone); String getTimeZone(); List<List<?>> getFilteredValues(); static List<Map<String, Object>> getValuesAsRows(List<List<?>> values, List<String> columns); static List<List<?>> getValuesAsMatrix(List<List<?>> values); static Map<String, Object> getValuesAsDictionary(List<List<?>> values); List<Map<String, Object>> getValuesAsRows(); List<List<?>> getValuesAsMatrix(); Map<String, Object> getValuesAsDictionary(); List<List<?>> getValues(); List<String> getColumnNames(); List<String> getTypes(); String getSubtype(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String TABLE_DISPLAY_SUBTYPE; static final String LIST_OF_MAPS_SUBTYPE; static final String MATRIX_SUBTYPE; static final String DICTIONARY_SUBTYPE; } | @Test public void getValuesAsDictionaryWithParam_returnedMapIsNotEmpty() throws Exception { Map<String, Object> dictionary = TableDisplay.getValuesAsDictionary(Arrays.asList(Arrays.asList("k1", 1), Arrays.asList("k2", 2))); Assertions.assertThat(dictionary).isNotEmpty(); } |
TableDisplayAlignmentSerializer extends JsonSerializer<TableDisplayAlignmentProvider> { @Override public void serialize(TableDisplayAlignmentProvider value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { synchronized (value) { jgen.writeString(value.getCode()); } } @Override void serialize(TableDisplayAlignmentProvider value,
JsonGenerator jgen,
SerializerProvider provider); } | @Test public void serializeTableDisplayLeftAligment_resultJsonHasLValue() throws IOException { serializer.serialize( TableDisplayAlignmentProvider.LEFT_ALIGNMENT, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.asText()).isEqualTo("L"); } |
NamespaceClient { public synchronized static NamespaceClient getBeaker() { if (currentSession!=null){ return nsClients.get(currentSession); } return null; } NamespaceClient(); synchronized void showProgressUpdate(String message, int progress); SimpleEvaluationObject getOutputObj(); synchronized void setOutputObj(SimpleEvaluationObject input); synchronized static NamespaceClient getBeaker(); synchronized static NamespaceClient getBeaker(String session); synchronized static void delBeaker(String sessionId); synchronized Object set(String name, Object value); Object setFast(String name, Object value); Object unset(String name); synchronized Object get(final String name); static SynchronousQueue<Object> getMessageQueue(String channel); List<BeakerCodeCell> getCodeCells(String tagFilter); } | @Test public void getNamespaceClientBySessionId_returnNamespaceClient() { NamespaceClient curNamespaceClient = NamespaceClient.getBeaker(SESSION_ID); Assertions.assertThat(namespaceClient).isNotNull(); Assertions.assertThat(curNamespaceClient).isEqualTo(namespaceClient); }
@Test public void getNamespaceClientByCurrentSessionId_returnNamespaceClient() { NamespaceClient curNamespaceClient = NamespaceClient.getBeaker(); Assertions.assertThat(curNamespaceClient).isNotNull(); Assertions.assertThat(curNamespaceClient).isEqualTo(namespaceClient); } |
SelectMultipleSingleWidget extends ListComponent implements CommFunctionality, EasyFormWidget { @Override public void setValues(Collection<String> values) { super.setValues(values); this.widget.setOptions(values.stream().toArray(String[]::new)); } SelectMultipleSingleWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override void setSize(Integer size); @Override Integer getSize(); @Override void setValues(Collection<String> values); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setValues() throws Exception { String newValue = "2"; SelectMultipleSingleWidget widget = new SelectMultipleSingleWidget(); widget.setValues(asList("1", "2", "3")); kernel.clearPublishedMessages(); widget.setValue(newValue); verifyMsgForProperty(kernel, SelectMultiple.VALUE, "2"); } |
SelectMultipleSingleWidget extends ListComponent implements CommFunctionality, EasyFormWidget { @Override public void setSize(Integer size) { this.widget.setSize(size); } SelectMultipleSingleWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override void setSize(Integer size); @Override Integer getSize(); @Override void setValues(Collection<String> values); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setSize() throws Exception { Integer newValue = 2; SelectMultipleSingleWidget widget = new SelectMultipleSingleWidget(); widget.setValues(asList("1", "2", "3")); kernel.clearPublishedMessages(); widget.setSize(newValue); verifyMsgForProperty(kernel, SelectMultipleSingle.SIZE, 2); } |
CheckBoxWidget extends CheckBox implements CommFunctionality, EasyFormWidget { @Override public void setValue(String value) { this.widget.setValue(Boolean.valueOf(value)); } CheckBoxWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setValue() throws Exception { Boolean newValue = Boolean.TRUE; CheckBoxWidget widget = new CheckBoxWidget(); kernel.clearPublishedMessages(); widget.setValue(newValue.toString()); verifyValue(kernel.getPublishedMessages().get(0), newValue); } |
ComboBoxWidget extends ComboBox implements CommFunctionality, EasyFormWidget { @Override public void setValue(String value) { this.widget.setValue(value); } ComboBoxWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override void setValues(Collection<String> values); @Override void setEditable(Boolean editable); @Override void setValue(String value); @Override String getValue(); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setValue() throws Exception { String newValue = "2"; ComboBoxWidget widget = new ComboBoxWidget(); widget.setValues(asList("1", "2", "3")); kernel.clearPublishedMessages(); widget.setValue(newValue); verifyValue(kernel.getPublishedMessages().get(0), newValue); } |
ComboBoxWidget extends ComboBox implements CommFunctionality, EasyFormWidget { @Override public void setEditable(Boolean editable) { super.setEditable(editable); this.widget.setDisabled(editable); } ComboBoxWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override void setValues(Collection<String> values); @Override void setEditable(Boolean editable); @Override void setValue(String value); @Override String getValue(); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setEditable() throws Exception { Boolean newValue = Boolean.TRUE; ComboBoxWidget widget = new ComboBoxWidget(); kernel.clearPublishedMessages(); widget.setEditable(newValue); verifyEditable(kernel.getPublishedMessages().get(0), newValue); } |
TextFieldWidget extends TextField implements CommFunctionality, EasyFormWidget { @Override public void setValue(String value) { this.text.setValue(value); } TextFieldWidget(); @Override DOMWidget getWidget(); @Override String getLabel(); @Override void setLabel(String label); @Override void setValue(String value); @Override String getValue(); @Override Comm getComm(); @Override TextField setWidth(Integer width); @Override void close(); } | @Test public void setValue() throws Exception { String newValue = "newValue"; TextFieldWidget widget = new TextFieldWidget(); kernel.clearPublishedMessages(); widget.setValue(newValue); verifyTextFieldValue(kernel.getPublishedMessages().get(0), newValue); } |
TextFieldWidget extends TextField implements CommFunctionality, EasyFormWidget { @Override public TextField setWidth(Integer width) { text.getLayout().setWidth(width + PX); return super.setWidth(width); } TextFieldWidget(); @Override DOMWidget getWidget(); @Override String getLabel(); @Override void setLabel(String label); @Override void setValue(String value); @Override String getValue(); @Override Comm getComm(); @Override TextField setWidth(Integer width); @Override void close(); } | @Test public void setWidth() throws Exception { Integer newValue = 11; TextFieldWidget widget = new TextFieldWidget(); kernel.clearPublishedMessages(); widget.setWidth(newValue); verifyTextFieldWidth(kernel.getPublishedMessages().get(0), "11" + PX); } |
ButtonComponentWidget extends ButtonComponent implements CommFunctionality, EasyFormWidget { @Override public void setTag(String tag) { this.widget.setTag(tag); } ButtonComponentWidget(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getLabel(); @Override String getValue(); @Override void setValue(String value); @Override void setTag(String tag); @Override String getTag(); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setTag() throws Exception { String tag = "tag1"; ButtonComponentWidget widget = new ButtonComponentWidget(); kernel.clearPublishedMessages(); widget.setTag(tag); verifyTag(kernel.getPublishedMessages().get(0), tag); } |
ButtonComponentWidget extends ButtonComponent implements CommFunctionality, EasyFormWidget { @Override public Comm getComm() { return widget.getComm(); } ButtonComponentWidget(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getLabel(); @Override String getValue(); @Override void setValue(String value); @Override void setTag(String tag); @Override String getTag(); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void handleActionPerformed() throws Exception { final StringBuilder result = new StringBuilder(); ButtonComponentWidget widget = new ButtonComponentWidget(); widget.actionPerformed = value -> result.append("action done 1"); widget.getComm().getMsgCallbackList().forEach(x -> x.handle(messageWithClickEvent())); assertThat(result.toString()).isEqualTo("action done 1"); }
@Test public void noHandleActionPerformed() throws Exception { final StringBuilder result = new StringBuilder().append("no action"); ButtonComponentWidget widget = new ButtonComponentWidget(); widget.actionPerformed = value -> result.append("action done 2"); widget.getComm().getMsgCallbackList().forEach(x -> x.handle(messageWithoutClickEvent())); assertThat(result.toString()).isEqualTo("no action"); } |
SelectMultipleWidget extends ListComponent implements CommFunctionality, EasyFormWidget { @Override public void setValues(Collection<String> values) { super.setValues(values); this.widget.setOptions(values.stream().toArray(String[]::new)); } SelectMultipleWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override void setSize(Integer size); @Override Integer getSize(); @Override void setValues(Collection<String> values); void setValue(String[] value); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setValues() throws Exception { String[] newValue = new String[]{"1", "2"}; SelectMultipleWidget widget = new SelectMultipleWidget(); widget.setValues(asList("1", "2", "3")); kernel.clearPublishedMessages(); widget.setValue(newValue); verifyMsgForProperty(kernel, SelectMultiple.VALUE, new String[]{"1", "2"}); } |
SelectMultipleWidget extends ListComponent implements CommFunctionality, EasyFormWidget { @Override public void setSize(Integer size) { this.widget.setSize(size); } SelectMultipleWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override void setSize(Integer size); @Override Integer getSize(); @Override void setValues(Collection<String> values); void setValue(String[] value); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setSize() throws Exception { Integer newValue = 3; SelectMultipleWidget widget = new SelectMultipleWidget(); widget.setValues(asList("1", "2", "3")); kernel.clearPublishedMessages(); widget.setSize(newValue); verifyMsgForProperty(kernel, SelectMultiple.SIZE, 3); } |
DatePickerComponentWidget extends DatePickerComponent implements CommFunctionality, EasyFormWidget { @Override public void setShowTime(Boolean showTime) { this.widget.setShowTime(showTime); } DatePickerComponentWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override DOMWidget getWidget(); @Override void setShowTime(Boolean showTime); @Override Boolean getShowTime(); @Override void close(); } | @Test public void setShowTime() throws Exception { Boolean newValue = Boolean.TRUE; DatePickerComponentWidget widget = new DatePickerComponentWidget(); kernel.clearPublishedMessages(); widget.setShowTime(newValue); verifyShowTime(kernel.getPublishedMessages().get(0), true); } |
CheckBoxGroupWidget extends CheckBoxGroup implements CommFunctionality, EasyFormWidget { @Override public void setValues(Collection<String> values) { values.forEach(item -> { Checkbox checkbox = new Checkbox(); checkbox.setDescription(item); checkboxes.add(checkbox); }); } CheckBoxGroupWidget(); @Override String getLabel(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override Collection<String> getValues(); @Override void setValues(Collection<String> values); void createWidget(); @Override Comm getComm(); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setValues() throws Exception { List<String> newValue = Arrays.asList("1", "2", "3"); CheckBoxGroupWidget widget = new CheckBoxGroupWidget(); kernel.clearPublishedMessages(); widget.setValues(newValue); assertTrue("Comm msgs should be 9", kernel.getPublishedMessages().size() == 9); Assertions.assertThat(widget.getValues()).isEqualTo(EMPTY); } |
GroovyCommOpenHandler extends CommOpenHandler { public Handler<Message>[] getKernelControlChanelHandlers(String targetName){ if(TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)){ return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS; }else if(TargetNamesEnum.BEAKER_GETCODECELLS.getTargetName().equalsIgnoreCase(targetName)){ return (Handler<Message>[]) KERNEL_GET_CODECELLS_CHANNEL_HANDLER; } else{ return (Handler<Message>[]) new Handler<?>[0]; } } GroovyCommOpenHandler(KernelFunctionality kernel); Handler<Message>[] getKernelControlChanelHandlers(String targetName); } | @Test public void getControlHandlersWithEmptyString_returnEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(""); Assertions.assertThat(handlers).isEmpty(); }
@Test public void getControlHandlersWithTargetName_returnNotEmptyHandlersArray() throws Exception { Handler<Message>[] handlers = commOpenHandler.getKernelControlChanelHandlers(targetName); Assertions.assertThat(handlers).isNotEmpty(); } |
TextAreaWidget extends TextArea implements CommFunctionality, EasyFormWidget { @Override public void setValue(String value) { this.widget.setValue(value); } TextAreaWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override DOMWidget getWidget(); @Override void setWidth(Integer width); @Override void setHeight(Integer height); @Override void close(); } | @Test public void setValue() throws Exception { String newValue = "newValue"; TextAreaWidget widget = new TextAreaWidget(); kernel.clearPublishedMessages(); widget.setValue(newValue); verifyTextAreaValue(kernel.getPublishedMessages().get(0), newValue); } |
TextAreaWidget extends TextArea implements CommFunctionality, EasyFormWidget { @Override public void setWidth(Integer width) { super.setWidth(width); widget.getLayout().setWidth(width + PX); } TextAreaWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override DOMWidget getWidget(); @Override void setWidth(Integer width); @Override void setHeight(Integer height); @Override void close(); } | @Test public void setWidth() throws Exception { Integer newValue = 11; TextAreaWidget widget = new TextAreaWidget(); kernel.clearPublishedMessages(); widget.setWidth(newValue); verifyWidth(kernel.getPublishedMessages().get(0), "11" + PX); } |
TextAreaWidget extends TextArea implements CommFunctionality, EasyFormWidget { @Override public void setHeight(Integer height) { super.setHeight(height); widget.getLayout().setHeight(height + PX); } TextAreaWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override DOMWidget getWidget(); @Override void setWidth(Integer width); @Override void setHeight(Integer height); @Override void close(); } | @Test public void setHeight() throws Exception { Integer newValue = 22; TextAreaWidget widget = new TextAreaWidget(); kernel.clearPublishedMessages(); widget.setHeight(newValue); verifyHeight(kernel.getPublishedMessages().get(0), "22" + PX); } |
RadioButtonComponentWidget extends RadioButtonComponent implements CommFunctionality, EasyFormWidget { @Override public void setValues(Collection<String> values) { this.widget.setOptions(values.stream().toArray(String[]::new)); } RadioButtonComponentWidget(); @Override String getLabel(); @Override Comm getComm(); @Override void setLabel(String label); @Override String getValue(); @Override void setValue(String value); @Override void setValues(Collection<String> values); @Override Collection<String> getValues(); @Override DOMWidget getWidget(); @Override void close(); } | @Test public void setValues() throws Exception { String newValue = "2"; RadioButtonComponentWidget widget = new RadioButtonComponentWidget(); widget.setValues(asList("1", "2", "3")); kernel.clearPublishedMessages(); widget.setValue(newValue); verifyMsgForProperty(kernel, SelectMultiple.VALUE, "2"); } |
EasyFormView extends Box implements InternalCommWidget { public void setEasyFormName(String easyFormName) { this.easyFormName = easyFormName; sendUpdate(EASY_FORM_NAME, easyFormName); } EasyFormView(List<CommFunctionality> children); @Override void updateValue(Object value); String getEasyFormName(); void setEasyFormName(String easyFormName); String getModelNameValue(); String getViewNameValue(); static final String VIEW_NAME_VALUE; static final String MODEL_NAME_VALUE; static final String EASY_FORM_NAME; } | @Test public void shouldSendCommMsgWhenEasyFormNameChange() throws Exception { EasyFormView widget = easyForm(); widget.setEasyFormName("title2"); verifyMsgForProperty(groovyKernel, EasyFormView.EASY_FORM_NAME, "title2"); } |
CsvPlotReader { public List<Map<?, ?>> readAsList(String fileName) throws IOException { return convert(Table.createFromCsv(fileName)); } List<Map<?, ?>> convert(Table table); Table read(String fileName); List<Map<?, ?>> readAsList(String fileName); } | @Test public void shouldReturnDataAsListForPlot() throws Exception { List<Map<?, ?>> values = new CsvPlotReader().readAsList(getOsAppropriatePath("tableRowsTest.csv")); assertThat(values.get(2).get("m3")).isEqualTo(8.0f); assertThat(values.get(2).get("time")) .isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("1990-03-31").getTime()); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.