@@ -0,0 +1,2635 @@
+package tachyon.worker.keyvalue;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0A/**%0A * Unit tests of %7B@link LinearProbingIndex%7D.%0A */%0Apublic class LinearProbingIndexTest %7B%0A  private static final byte%5B%5D KEY1 = %22key1%22.getBytes();%0A  private static final byte%5B%5D KEY2 = %22key2_foo%22.getBytes();%0A%0A  @Test%0A  public void putBasicTest() throws Exception %7B%0A    LinearProbingIndex index = LinearProbingIndex.createEmptyIndex();%0A    Assert.assertEquals(0, index.keyCount());%0A    Assert.assertTrue(index.put(KEY1, 0));%0A    Assert.assertEquals(1, index.keyCount());%0A    Assert.assertTrue(index.put(KEY2, 1));%0A    Assert.assertEquals(2, index.keyCount());%0A  %7D%0A%0A  @Test%0A  public void putDuplicatedKeyTest() throws Exception %7B%0A    LinearProbingIndex index = LinearProbingIndex.createEmptyIndex();%0A    // TODO(binfan): change constant 50 to be LinearProbingIndex.MAX_PROBES%0A    for (int i = 0; i %3C 50; i ++) %7B%0A      Assert.assertEquals(i, index.keyCount());%0A      Assert.assertTrue(index.put(KEY1, 0));%0A    %7D%0A    Assert.assertFalse(index.put(KEY1, 0));%0A  %7D%0A%0A  @Test%0A  public void getInsertedKeysTest() throws Exception %7B%0A    // Initialize a batch of key-value pairs%0A    int test_keys = 100;%0A    byte%5B%5D%5B%5D keys = new byte%5Btest_keys%5D%5B%5D;%0A    byte%5B%5D%5B%5D values = new byte%5Btest_keys%5D%5B%5D;%0A    for (int i = 0; i %3C test_keys; i ++) %7B%0A      keys%5Bi%5D = String.format(%22test-key:%25d%22, i).getBytes();%0A      values%5Bi%5D = String.format(%22test-val:%25d%22, i).getBytes();%0A    %7D%0A%0A    LinearProbingIndex index = LinearProbingIndex.createEmptyIndex();%0A%0A    // Insert this batch of key-value pairs%0A    Utils.MockOutputStream mockOutput = new Utils.MockOutputStream(10000);%0A    PayloadWriter payloadWriter = new PayloadWriter(mockOutput);%0A    for (int i = 0; i %3C test_keys; i ++) %7B%0A      int offset = mockOutput.getCount();%0A      payloadWriter.addKeyAndValue(keys%5Bi%5D, values%5Bi%5D);%0A      payloadWriter.flush();%0A      Assert.assertTrue(index.put(keys%5Bi%5D, offset));%0A      Assert.assertEquals(i + 1, index.keyCount());%0A    %7D%0A    payloadWriter.close();%0A%0A    // Read all keys back, expect same value as inserted%0A    PayloadReader payloadReader = new PayloadReader(mockOutput.toByteArray());%0A    for (int i = 0; i %3C test_keys; i ++) %7B%0A      byte%5B%5D value = index.get(keys%5Bi%5D, payloadReader);%0A      Assert.assertArrayEquals(values%5Bi%5D, value);%0A    %7D%0A  %7D%0A%0A  @Test%0A  public void getNonExistentKeyTest() throws Exception %7B%0A    LinearProbingIndex index = LinearProbingIndex.createEmptyIndex();%0A    PayloadReader payloadReaderNotUsed = new PayloadReader(new byte%5B%5D %7B%7D);%0A    byte%5B%5D nonExistentKey = %22NotInserted%22.getBytes();%0A    Assert.assertNull(index.get(nonExistentKey, payloadReaderNotUsed));%0A  %7D%0A%7D%0A

Add unit tests of LinearProbingIndex