コード例 #1
0
  /**
   * 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());
  }
コード例 #2
0
  /**
   * 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());
  }