Search in sources :

Example 6 with Version

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());
}
Also used : Version(io.pravega.client.tables.Version) Test(org.junit.Test)

Example 7 with Version

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);
}
Also used : TableEntry(io.pravega.client.tables.TableEntry) Version(io.pravega.client.tables.Version) TableKey(io.pravega.client.tables.TableKey) ByteBuffer(java.nio.ByteBuffer)

Example 8 with Version

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);
}
Also used : lombok.val(lombok.val) BadKeyVersionException(io.pravega.client.tables.BadKeyVersionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Version(io.pravega.client.tables.Version) TableKey(io.pravega.client.tables.TableKey) Cleanup(lombok.Cleanup) Put(io.pravega.client.tables.Put) Test(org.junit.Test)

Aggregations

Version (io.pravega.client.tables.Version)8 TableKey (io.pravega.client.tables.TableKey)7 Test (org.junit.Test)7 BadKeyVersionException (io.pravega.client.tables.BadKeyVersionException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Cleanup (lombok.Cleanup)6 lombok.val (lombok.val)6 Insert (io.pravega.client.tables.Insert)5 Put (io.pravega.client.tables.Put)5 Remove (io.pravega.client.tables.Remove)4 TableEntry (io.pravega.client.tables.TableEntry)4 ByteBuffer (java.nio.ByteBuffer)4 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)3 Serializer (io.pravega.client.stream.Serializer)3 KeyValueTable (io.pravega.client.tables.KeyValueTable)3 KeyValueTableConfiguration (io.pravega.client.tables.KeyValueTableConfiguration)3 TableModification (io.pravega.client.tables.TableModification)3 BitConverter (io.pravega.common.util.BitConverter)3 AssertExtensions (io.pravega.test.common.AssertExtensions)3 LeakDetectorTestSuite (io.pravega.test.common.LeakDetectorTestSuite)3