/**
   * Test getMetadata API with a serial of entries. The entries have already existed in
   * simulator/drive. The test result should be successful.
   *
   * <p>
   *
   * @throws KineticException if any internal error occurred.
   */
  @Test(dataProvider = "transportProtocolOptions")
  public void testGetMetadata_ReturnsMetadata_ForExistingKey(String clientName)
      throws KineticException {
    byte[] newVersion = int32(0);
    // String alg = Message.Algorithm.INVALID_ALGORITHM.toString();

    cleanKVGenData(MAX_KEYS, getClient(clientName));

    for (int i = 0; i < MAX_KEYS; i++) {
      String keyS = kvGenerator.getNextKey();
      String valueS = kvGenerator.getValue(keyS);

      EntryMetadata entryMetadata = new EntryMetadata();
      Entry entry = new Entry(toByteArray(keyS), toByteArray(valueS), entryMetadata);
      getClient(clientName).put(entry, newVersion);

      EntryMetadata entryMetadataGet;
      entryMetadataGet = getClient(clientName).getMetadata(toByteArray(keyS));
      assertArrayEquals(newVersion, entryMetadataGet.getVersion());

      // XXX chiaming 04/12/2013: default enum is not valid, need to be
      // evaluated.
      // assertEquals(alg, entryMetadataGet.getAlgorithm());
    }

    cleanKVGenData(MAX_KEYS, getClient(clientName));

    logger.info(this.testEndInfo());
  }
  /**
   * Test put API with a serial of entries. Metadata with the value of algorithm, without algorithm
   * The test result should be successful and verify the result returned is the same as put before
   *
   * <p>
   *
   * @throws KineticException if any internal error occurred.
   */
  @Test(dataProvider = "transportProtocolOptions")
  public void testPut_MetadataWithoutTag(String clientName) throws KineticException {
    Entry versionedPut;
    Entry versionedPutReturn;
    byte[] key;
    byte[] value;
    String algorithm = "SHA1";
    Long start = System.nanoTime();

    cleanData(MAX_KEYS, getClient(clientName));

    for (int i = 0; i < MAX_KEYS; i++) {
      key = toByteArray(KEY_PREFIX + i);
      value = ByteBuffer.allocate(8).putLong(start + i).array();
      EntryMetadata entryMetadata = new EntryMetadata();
      entryMetadata.setAlgorithm(algorithm);
      versionedPut = new Entry(key, value, entryMetadata);

      versionedPutReturn = getClient(clientName).put(versionedPut, int32(i));
      assertArrayEquals(key, versionedPutReturn.getKey());
      assertArrayEquals(int32(i), versionedPutReturn.getEntryMetadata().getVersion());
      assertArrayEquals(value, versionedPutReturn.getValue());
      assertArrayEquals(null, versionedPutReturn.getEntryMetadata().getTag());
      assertEquals("SHA1", versionedPutReturn.getEntryMetadata().getAlgorithm());
    }

    cleanData(MAX_KEYS, getClient(clientName));

    logger.info(this.testEndInfo());
  }
  /**
   * Test delete API with a entry has not existed in simulator/drive. The test result should be
   * false.
   *
   * <p>
   *
   * @throws KineticException if any internal error occurred.
   */
  @Test(dataProvider = "transportProtocolOptions")
  public void testDelete_ReturnsFalse_ForMissingKey(String clientName) throws KineticException {
    byte[] key = toByteArray("asdfgh#$@257");
    assertKeyNotFound(getClient(clientName), key);

    // delete key which does not exist in Simulator/Drive
    byte[] value = toByteArray("value");
    EntryMetadata entryMetadata = new EntryMetadata();
    entryMetadata.setVersion(int32(0));
    Entry versioned = new Entry(key, value, entryMetadata);
    assertFalse(getClient(clientName).delete(versioned));

    logger.info(this.testEndInfo());
  }
  /**
   * Test putForced API result with a serial entries. The entries have already existed in
   * simulator/drive. Give new entry with db version different with version in simulator/drive, the
   * test result should be successful.
   *
   * <p>
   *
   * @throws KineticException if any internal error occurred.
   */
  @Test(dataProvider = "transportProtocolOptions")
  public void testPutForced(String clientName) throws KineticException {
    Long start = System.nanoTime();

    cleanData(MAX_KEYS, getClient(clientName));

    for (int i = 0; i < MAX_KEYS; i++) {
      byte[] key = toByteArray(KEY_PREFIX + i);
      byte[] value = ByteBuffer.allocate(8).putLong(start + i).array();
      EntryMetadata entryMetadata = new EntryMetadata();
      Entry versionedPut = new Entry(key, value, entryMetadata);

      getClient(clientName).put(versionedPut, int32(i));
    }

    start = System.nanoTime();
    byte[] version = int32(8);
    for (int i = 0; i < MAX_KEYS; i++) {
      byte[] key = toByteArray(KEY_PREFIX + i);
      byte[] value = ByteBuffer.allocate(8).putLong(start + i).array();

      EntryMetadata entryMetadata = new EntryMetadata();

      entryMetadata.setVersion(version);

      Entry versionedPutForced = new Entry(key, value, entryMetadata);

      getClient(clientName).putForced(versionedPutForced);

      Entry entryGet = getClient(clientName).get(key);
      assertArrayEquals(key, entryGet.getKey());
      assertArrayEquals(version, entryGet.getEntryMetadata().getVersion());
      assertArrayEquals(value, entryGet.getValue());
    }

    cleanData(MAX_KEYS, getClient(clientName));

    logger.info(this.testEndInfo());
  }