Search in sources :

Example 6 with CachedFileStatus

use of org.smartdata.model.CachedFileStatus in project SSM by Intel-bigdata.

the class TestMetaStore method testUpdateCachedFiles.

@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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CachedFileStatus(org.smartdata.model.CachedFileStatus) FileAccessEvent(org.smartdata.metrics.FileAccessEvent) Test(org.junit.Test)

Example 7 with CachedFileStatus

use of org.smartdata.model.CachedFileStatus in project SSM by Intel-bigdata.

the class TestMetaStore method testGetCachedFileStatus.

@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);
}
Also used : CachedFileStatus(org.smartdata.model.CachedFileStatus) Test(org.junit.Test)

Example 8 with CachedFileStatus

use of org.smartdata.model.CachedFileStatus in project SSM by Intel-bigdata.

the class TestCacheFileDao method testUpdateCachedFiles.

@Test
public void testUpdateCachedFiles() throws Exception {
    CachedFileStatus first = new CachedFileStatus(80L, "testPath", 1000L, 2000L, 100);
    cacheFileDao.insert(first);
    CachedFileStatus second = new CachedFileStatus(90L, "testPath2", 2000L, 3000L, 200);
    cacheFileDao.insert(second);
    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));
    // Sync status
    first.setLastAccessTime(4000L);
    first.setNumAccessed(first.getNumAccessed() + 2);
    second.setLastAccessTime(5000L);
    second.setNumAccessed(second.getNumAccessed() + 2);
    cacheFileDao.update(pathToId, events);
    List<CachedFileStatus> statuses = cacheFileDao.getAll();
    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 dbFirst = statusMap.get(80L);
    Assert.assertTrue(dbFirst.equals(first));
    Assert.assertTrue(statusMap.containsKey(90L));
    CachedFileStatus dbSecond = statusMap.get(90L);
    Assert.assertTrue(dbSecond.equals(second));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CachedFileStatus(org.smartdata.model.CachedFileStatus) FileAccessEvent(org.smartdata.metrics.FileAccessEvent) Test(org.junit.Test)

Aggregations

CachedFileStatus (org.smartdata.model.CachedFileStatus)8 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 FileAccessEvent (org.smartdata.metrics.FileAccessEvent)3 LinkedList (java.util.LinkedList)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 CacheFileAction (org.smartdata.hdfs.action.CacheFileAction)1 UncacheFileAction (org.smartdata.hdfs.action.UncacheFileAction)1 FileInfo (org.smartdata.model.FileInfo)1 SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)1