Search in sources :

Example 16 with GetResult

use of com.ctriposs.sdb.table.GetResult in project sessdb by ppdai.

the class HashMapTableTest method testReOpen.

@Test
public void testReOpen() throws IOException {
    long createdTime = System.nanoTime();
    mapTable = new HashMapTable(testDir, 0, createdTime);
    assertTrue(mapTable.getLevel() == 0);
    assertTrue(mapTable.getCreatedTime() == createdTime);
    assertTrue(mapTable.getAppendedSize() == 0);
    assertTrue(mapTable.isEmpty());
    assertTrue(mapTable.getBackFileSize() == HashMapTable.INIT_INDEX_FILE_SIZE + HashMapTable.INIT_DATA_FILE_SIZE + HashMapTable.INDEX_ITEM_LENGTH);
    int loop = 1024;
    for (int i = 0; i < loop; i++) {
        mapTable.appendNew(("key" + i).getBytes(), ("value" + i).getBytes(), -1, System.currentTimeMillis());
    }
    assertTrue(mapTable.getAppendedSize() == loop);
    mapTable.close();
    mapTable = new HashMapTable(testDir, 0, createdTime);
    for (int i = 0; i < loop; i++) {
        IMapEntry mapEntry = mapTable.getMapEntry(i);
        assertTrue(Arrays.equals(("key" + i).getBytes(), mapEntry.getKey()));
        assertTrue(Arrays.equals(("value" + i).getBytes(), mapEntry.getValue()));
        assertTrue(-1 == mapEntry.getTimeToLive());
        assertTrue(System.currentTimeMillis() >= mapEntry.getCreatedTime());
        assertFalse(mapEntry.isDeleted());
        assertTrue(mapEntry.isInUse());
    }
    try {
        mapTable.getMapEntry(loop);
    } catch (IllegalArgumentException iae) {
    }
    for (int i = 0; i < loop; i++) {
        GetResult result = mapTable.get(("key" + i).getBytes());
        assertTrue(result.isFound());
        assertFalse(result.isDeleted() || result.isExpired());
        assertTrue(Arrays.equals(("value" + i).getBytes(), result.getValue()));
    }
    GetResult result = mapTable.get(("key" + loop).getBytes());
    assertFalse(result.isFound());
    assertFalse(result.isDeleted() || result.isExpired());
}
Also used : GetResult(com.ctriposs.sdb.table.GetResult) IMapEntry(com.ctriposs.sdb.table.IMapEntry) HashMapTable(com.ctriposs.sdb.table.HashMapTable) Test(org.junit.Test)

Example 17 with GetResult

use of com.ctriposs.sdb.table.GetResult in project sessdb by ppdai.

the class MMFMapTableTest method testEmtpy.

@Test
public void testEmtpy() throws IOException, ClassNotFoundException {
    long createdTime = System.nanoTime();
    mapTable = new MMFMapTable(testDir, 1, createdTime, 1000, 4);
    assertTrue(mapTable.getLevel() == 1);
    assertTrue(mapTable.getCreatedTime() == createdTime);
    assertTrue(mapTable.getAppendedSize() == 0);
    assertTrue(mapTable.isEmpty());
    //assertTrue(mapTable.getBackFileSize() == (MMFMapTable.INIT_INDEX_FILE_SIZE + MMFMapTable.INIT_DATA_FILE_SIZE) * Level0Merger.DEFAULT_MERGE_WAYS);
    assertFalse(mapTable.isUsable());
    try {
        @SuppressWarnings("unused") GetResult result = mapTable.get("empty".getBytes());
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        mapTable.getMapEntry(-1);
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        mapTable.getMapEntry(0);
        fail();
    } catch (IllegalArgumentException iae) {
    }
}
Also used : MMFMapTable(com.ctriposs.sdb.table.MMFMapTable) GetResult(com.ctriposs.sdb.table.GetResult) Test(org.junit.Test)

Aggregations

GetResult (com.ctriposs.sdb.table.GetResult)17 Test (org.junit.Test)16 HashMapTable (com.ctriposs.sdb.table.HashMapTable)8 MMFMapTable (com.ctriposs.sdb.table.MMFMapTable)7 ArrayList (java.util.ArrayList)7 IMapEntry (com.ctriposs.sdb.table.IMapEntry)6 FCMapTable (com.ctriposs.sdb.table.FCMapTable)5 LevelQueue (com.ctriposs.sdb.LevelQueue)4 Random (java.util.Random)4 IOException (java.io.IOException)2 AbstractMapTable (com.ctriposs.sdb.table.AbstractMapTable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1