/** * 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()); }
@Override public void onSuccess(CallbackResult<Entry> result) { Entry entryGet = result.getResult(); String entryGetAsString = new String(entryGet.getKey()) + ":" + new String(entry.getValue()); // check whether the entry I got is as same as the previous put if (Arrays.equals(entry.getKey(), entryGet.getKey()) && Arrays.equals(entry.getValue(), entryGet.getValue())) { // remove the entry from put hash map handlers.remove(entryGetAsString); System.out.println("Entry " + entryGetAsString + " passed the checking."); } else { throw new RuntimeException( "Can't get the right entry back for the " + new String(entry.getKey()) + " put"); } }
/** * 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()); }