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());
}
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) {
}
}
Aggregations