@Test
public void testCase01() throws IOException, ClassNotFoundException {

	
	String value = TestUtil.randomString(128);
	
	HashMapTable[] sourceTables = new HashMapTable[4];
	LevelQueue lq0 = new LevelQueue();
	for(int i = 0; i < 4; i++) {
		sourceTables[i] = new HashMapTable(testDir, SDB.LEVEL0, System.nanoTime() + i);
		sourceTables[i].setCompressionEnabled(true);
		lq0.addFirst(sourceTables[i]);
		assertTrue(sourceTables[i].isImmutable());
	}
	
	int totalCount = 0;
	int max = 0;
	for(int i = 0; i < 4; i++) {
		int start = i;
		HashMapTable table = sourceTables[i];
		while(table.put(String.valueOf(start).getBytes(), value.getBytes(), AbstractMapTable.NO_TIMEOUT, System.currentTimeMillis(), false)) {
			totalCount++;
			if (start > max) max = start;
			start = start + 4;
		}
	}
	
	LevelQueue lq1 = new LevelQueue();
	
	long start = System.currentTimeMillis();
	Level0Merger.mergeSort(lq0, lq1, 4, testDir, (short)1);
	long end = System.currentTimeMillis();
	System.out.println("Time spent to merge " + totalCount + " items in 4 ways  is " + (end - start) / 1000 + "s");
	
	for(int i = 0; i < 4; i++) {
		assertTrue(sourceTables[i].isImmutable());
	}
	
	assertTrue(lq1.size() == 1);
	MMFMapTable targetTable = (MMFMapTable) lq1.poll();
	assertTrue(targetTable.getLevel() == SDB.LEVEL1);
	assertTrue(targetTable.getAppendedSize() == totalCount);
	
	List<String> keyList = new ArrayList<String>();
	for(long i = 0; i < totalCount; i++) {
		keyList.add(String.valueOf(i));
	}
	Collections.sort(keyList, new Comparator<String>() {
		@Override
		public int compare(String arg0, String arg1) {
			int hash0 = Arrays.hashCode(arg0.getBytes());
			int hash1 = Arrays.hashCode(arg1.getBytes());
			if (hash0 < hash1) return -1;
			else if (hash0 > hash1) return 1;
			else return 0;
		}
		
	});
	
	for(int i = 0; i < totalCount; i++) {
		IMapEntry mapEntry = targetTable.getMapEntry(i);
		assertTrue(mapEntry.getIndex() == i);
		assertTrue(new String(mapEntry.getKey()).equals(keyList.get(i)));
		assertTrue(new String(Snappy.uncompress(mapEntry.getValue())).equals(value));
	}
	
	start = System.currentTimeMillis();
	Random random = new Random();
	for(int i = 0; i < 1024; i++) {
		long key = random.nextInt(totalCount);
		GetResult result = targetTable.get(String.valueOf(key).getBytes());
		assertTrue(result.isFound());
	}
	end = System.currentTimeMillis();
	System.out.println("Time to lookup 1024 random key in the target table is " + (end - start) + "ms");
	
	targetTable.close();
	targetTable.delete();
}