@Override
 @Test
 public void testNullKeys() throws Exception {
   System.out.println("                    Testing null Keys                    ");
   Store<ByteArray, byte[], byte[]> store = getStore();
   try {
     store.put(null, new Versioned<byte[]>(getValue(), getNewIncrementedVectorClock()), null);
     fail("Store should not put null keys!");
   } catch (IllegalArgumentException e) {
     // this is good
   } catch (NullPointerException npe) {
     // this is good
   }
   try {
     store.get(null, null);
     fail("Store should not get null keys!");
   } catch (IllegalArgumentException e) {
     // this is good
   } catch (NullPointerException npe) {
     // this is good
   }
   try {
     store.getAll(null, null);
     fail("Store should not getAll null keys!");
   } catch (IllegalArgumentException e) {
     // this is good
   } catch (NullPointerException npe) {
     // this is good
   }
   try {
     store.getAll(
         Collections.<ByteArray>singleton(null),
         Collections.<ByteArray, byte[]>singletonMap(null, null));
     fail("Store should not getAll null keys!");
   } catch (IllegalArgumentException e) {
     // this is good
   } catch (NullPointerException npe) {
     // this is good
   }
   try {
     store.delete(null, new VectorClock());
     fail("Store should not delete null keys!");
   } catch (IllegalArgumentException e) {
     // this is good
   } catch (NullPointerException npe) {
     // this is good
   }
 }
  @Test
  public void testGetAllWithBinaryData() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    List<ByteArray> keys = Lists.newArrayList();
    List<byte[]> values = Lists.newArrayList();

    // The Byte 0x8c is interesting, because if you use GetContent method of
    // MimeBodyPart it gets converted to 0xc2 and 0x8c
    // This thread tracks this question
    // http://stackoverflow.com/questions/23023583/mimebodypart-getcontent-corrupts-binary-data

    byte[] interestingByte = new byte[] {(byte) 0x8c};
    ByteArray interestingKey = new ByteArray(interestingByte);

    keys.add(interestingKey);
    values.add(interestingByte);

    // Add all possible byte values
    byte[] allPossibleBytes = getAllPossibleBytes();
    ByteArray allPossibleKey = new ByteArray(allPossibleBytes);
    keys.add(allPossibleKey);
    values.add(allPossibleBytes);

    assertEquals(keys.size(), values.size());
    int count = keys.size();

    for (int i = 0; i < count; i++) {
      VectorClock vc = getClock(0, 0);
      store.put(keys.get(i), new Versioned<byte[]>(values.get(i), vc), null);
    }

    Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keys, null);
    assertGetAllValues(keys, values, result);
  }
  @Ignore
  @Test
  public void testHintedHandoff() throws Exception {
    Set<Integer> failedNodes = getFailedNodes();
    Multimap<Integer, ByteArray> failedKeys = populateStore(failedNodes);

    Map<ByteArray, byte[]> dataInSlops = Maps.newHashMap();
    Set<ByteArray> slopKeys = makeSlopKeys(failedKeys, Slop.Operation.PUT);

    for (Store<ByteArray, Slop, byte[]> slopStore : slopStores.values()) {
      Map<ByteArray, List<Versioned<Slop>>> res = slopStore.getAll(slopKeys, null);
      for (Map.Entry<ByteArray, List<Versioned<Slop>>> entry : res.entrySet()) {
        Slop slop = entry.getValue().get(0).getValue();
        dataInSlops.put(slop.getKey(), slop.getValue());

        if (logger.isTraceEnabled()) logger.trace(slop);
      }
    }

    for (Map.Entry<Integer, ByteArray> failedKey : failedKeys.entries()) {
      byte[] expected = keyValues.get(failedKey.getValue()).get();
      byte[] actual = dataInSlops.get(failedKey.getValue());

      assertNotNull("data should be stored in the slop", actual);
      assertEquals("correct should be stored in slop", 0, ByteUtils.compare(actual, expected));
    }
  }
  @Test
  @Ignore
  public void testDeleteHandoff() throws Exception {
    populateStore(Sets.<Integer>newHashSet());

    Map<ByteArray, Version> versions = Maps.newHashMap();
    for (ByteArray key : keyValues.keySet())
      versions.put(key, store.get(key, null).get(0).getVersion());

    Set<Integer> failedNodes = getFailedNodes();
    Multimap<Integer, ByteArray> failedKeys = ArrayListMultimap.create();

    for (ByteArray key : keysToNodes.keySet()) {
      Iterable<Integer> nodes = keysToNodes.get(key);

      for (int i = 0; i < REPLICATION_FACTOR; i++) {
        int node = Iterables.get(nodes, i);
        if (failedNodes.contains(node)) {
          failedKeys.put(node, key);
          break;
        }
      }
    }

    for (Map.Entry<Integer, ByteArray> failedKey : failedKeys.entries()) {
      try {
        store.delete(failedKey.getValue(), versions.get(failedKey.getValue()));
      } catch (Exception e) {
        if (logger.isTraceEnabled()) logger.trace(e, e);
      }
    }

    Set<ByteArray> slopKeys = makeSlopKeys(failedKeys, Slop.Operation.DELETE);
    Set<ByteArray> keysInSlops = Sets.newHashSet();

    for (Store<ByteArray, Slop, byte[]> slopStore : slopStores.values()) {
      Map<ByteArray, List<Versioned<Slop>>> res = slopStore.getAll(slopKeys, null);
      for (Map.Entry<ByteArray, List<Versioned<Slop>>> entry : res.entrySet()) {
        Slop slop = entry.getValue().get(0).getValue();
        keysInSlops.add(slop.getKey());

        if (logger.isTraceEnabled()) logger.trace(slop);
      }
    }

    for (Map.Entry<Integer, ByteArray> failedKey : failedKeys.entries())
      assertTrue(
          "delete operation for " + failedKey.getValue() + " should be handed off",
          keysInSlops.contains(failedKey.getValue()));
  }
  @Override
  @Test
  public void testGetAll() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    int putCount = 10;
    List<ByteArray> keys = getKeys(putCount);
    List<byte[]> values = getValues(putCount);
    assertEquals(putCount, values.size());
    for (int i = 0; i < putCount; i++) {
      VectorClock vc = getClock(0, 0);
      store.put(keys.get(i), new Versioned<byte[]>(values.get(i), vc), null);
    }

    int countForGet = putCount / 2;
    List<ByteArray> keysForGet = keys.subList(0, countForGet);
    List<byte[]> valuesForGet = values.subList(0, countForGet);
    Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keysForGet, null);
    assertGetAllValues(keysForGet, valuesForGet, result);
  }
 private VProto.GetAllResponse handleGetAll(
     VProto.GetAllRequest request, Store<ByteArray, byte[]> store) {
   VProto.GetAllResponse.Builder response = VProto.GetAllResponse.newBuilder();
   try {
     List<ByteArray> keys = new ArrayList<ByteArray>(request.getKeysCount());
     for (ByteString string : request.getKeysList()) keys.add(ProtoUtils.decodeBytes(string));
     Map<ByteArray, List<Versioned<byte[]>>> values = store.getAll(keys);
     for (Map.Entry<ByteArray, List<Versioned<byte[]>>> entry : values.entrySet()) {
       VProto.KeyedVersions.Builder keyedVersion =
           VProto.KeyedVersions.newBuilder().setKey(ProtoUtils.encodeBytes(entry.getKey()));
       for (Versioned<byte[]> version : entry.getValue())
         keyedVersion.addVersions(ProtoUtils.encodeVersioned(version));
       response.addValues(keyedVersion);
     }
   } catch (VoldemortException e) {
     response.setError(ProtoUtils.encodeError(getErrorMapper(), e));
   }
   return response.build();
 }