Search in sources :

Example 6 with Transaction

use of org.apache.distributedlog.util.Transaction in project bookkeeper by apache.

the class TestZKLogSegmentMetadataStore method testStoreMaxTxnId.

@Test(timeout = 60000)
public void testStoreMaxTxnId() throws Exception {
    Transaction<Object> updateTxn = lsmStore.transaction();
    Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(0));
    final CompletableFuture<Version> result = new CompletableFuture<Version>();
    LogMetadataForWriter metadata = mock(LogMetadataForWriter.class);
    when(metadata.getMaxTxIdPath()).thenReturn(rootZkPath);
    lsmStore.storeMaxTxnId(updateTxn, metadata, value, new Transaction.OpListener<Version>() {

        @Override
        public void onCommit(Version r) {
            result.complete(r);
        }

        @Override
        public void onAbort(Throwable t) {
            result.completeExceptionally(t);
        }
    });
    Utils.ioResult(updateTxn.execute());
    assertEquals(1L, ((LongVersion) Utils.ioResult(result)).getLongVersion());
    Stat stat = new Stat();
    byte[] data = zkc.get().getData(rootZkPath, false, stat);
    assertEquals(999L, DLUtils.deserializeTransactionId(data));
    assertEquals(1, stat.getVersion());
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) CompletableFuture(java.util.concurrent.CompletableFuture) Stat(org.apache.zookeeper.data.Stat) Transaction(org.apache.distributedlog.util.Transaction) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Version(org.apache.bookkeeper.versioning.Version) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogMetadataForWriter(org.apache.distributedlog.metadata.LogMetadataForWriter) Test(org.junit.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)6 LongVersion (org.apache.bookkeeper.versioning.LongVersion)6 Version (org.apache.bookkeeper.versioning.Version)6 Versioned (org.apache.bookkeeper.versioning.Versioned)6 Transaction (org.apache.distributedlog.util.Transaction)6 Test (org.junit.Test)6 ZKException (org.apache.distributedlog.exceptions.ZKException)4 Stat (org.apache.zookeeper.data.Stat)4 LogMetadata (org.apache.distributedlog.metadata.LogMetadata)3 LogMetadataForWriter (org.apache.distributedlog.metadata.LogMetadataForWriter)3