use of io.pravega.client.tables.Version in project pravega by pravega.
the class VersionImplTests method testConstructor.
@Test
public void testConstructor() {
long version = 123L;
long segmentId = 8946L;
Version v = new VersionImpl(segmentId, version);
Assert.assertEquals(version, v.asImpl().getSegmentVersion());
}
use of io.pravega.client.tables.Version in project pravega by pravega.
the class TableEntryHelper method fromTableSegmentEntry.
TableEntry fromTableSegmentEntry(TableSegment s, TableSegmentEntry e) {
if (e == null) {
return null;
}
Version version = new VersionImpl(s.getSegmentId(), e.getKey().getVersion());
TableKey key = fromTableSegmentKey(e.getKey());
ByteBuffer value = deserializeValue(e.getValue());
return new TableEntry(key, version, value);
}
use of io.pravega.client.tables.Version in project pravega by pravega.
the class KeyValueTableTestBase method testSingleKeyUpdates.
/**
* Tests the ability to perform single-key updates and replacements. These methods are exercised:
* - {@link KeyValueTable#update} with {@link Put} instances.
* - {@link KeyValueTable#get} and {@link KeyValueTable#getAll}.
*/
@Test
public void testSingleKeyUpdates() {
val versions = new Versions();
@Cleanup val kvt = createKeyValueTable();
// Put (unconditional update).
val iteration = new AtomicInteger(0);
forEveryKey((pk, sk) -> {
val value = getValue(pk, sk, iteration.get());
Version kv = kvt.update(new Put(new TableKey(pk, sk), value)).join();
versions.add(getUniqueKeyId(pk, sk), kv);
});
checkValues(iteration.get(), versions, kvt);
// Put (conditional update (not insertion)).
iteration.incrementAndGet();
forEveryKey((pk, sk) -> {
val value = getValue(pk, sk, iteration.get());
val keyId = getUniqueKeyId(pk, sk);
val existingVersion = versions.get(keyId);
// Verify that conditions are checked both for segment names and their versions.
val pkValue = Math.abs(PK_SERIALIZER.deserialize(pk));
Version badVersion = alterVersion(existingVersion, pkValue % 2 == 0, pkValue % 2 == 1);
AssertExtensions.assertSuppliedFutureThrows("update(Put-Conditional) did not throw for bad version.", () -> kvt.update(new Put(new TableKey(pk, sk), value, badVersion)), ex -> ex instanceof BadKeyVersionException);
Version kv = kvt.update(new Put(new TableKey(pk, sk), value, existingVersion)).join();
versions.add(keyId, kv);
});
checkValues(iteration.get(), versions, kvt);
}
Aggregations