Search in sources :

Example 1 with LogMetadata

use of org.apache.distributedlog.metadata.LogMetadata in project bookkeeper by apache.

the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumberBadVersion.

@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumberBadVersion() throws Exception {
    Transaction<Object> updateTxn = lsmStore.transaction();
    Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(10));
    final CompletableFuture<Version> result = new CompletableFuture<Version>();
    LogMetadata metadata = mock(LogMetadata.class);
    when(metadata.getLogSegmentsPath()).thenReturn(rootZkPath);
    lsmStore.storeMaxLogSegmentSequenceNumber(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);
        }
    });
    try {
        Utils.ioResult(updateTxn.execute());
        fail("Should fail on storing log segment sequence number if providing bad version");
    } catch (ZKException zke) {
        assertEquals(KeeperException.Code.BADVERSION, zke.getKeeperExceptionCode());
    }
    try {
        Utils.ioResult(result);
        fail("Should fail on storing log segment sequence number if providing bad version");
    } catch (ZKException ze) {
        assertEquals(KeeperException.Code.BADVERSION, ze.getKeeperExceptionCode());
    }
    Stat stat = new Stat();
    byte[] data = zkc.get().getData(rootZkPath, false, stat);
    assertEquals(0, stat.getVersion());
    assertEquals(0, data.length);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) CompletableFuture(java.util.concurrent.CompletableFuture) ZKException(org.apache.distributedlog.exceptions.ZKException) 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) LogMetadata(org.apache.distributedlog.metadata.LogMetadata) Test(org.junit.Test)

Example 2 with LogMetadata

use of org.apache.distributedlog.metadata.LogMetadata in project bookkeeper by apache.

the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumber.

@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumber() throws Exception {
    Transaction<Object> updateTxn = lsmStore.transaction();
    Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(0));
    final CompletableFuture<Version> result = new CompletableFuture<Version>();
    LogMetadata metadata = mock(LogMetadata.class);
    when(metadata.getLogSegmentsPath()).thenReturn(rootZkPath);
    lsmStore.storeMaxLogSegmentSequenceNumber(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.deserializeLogSegmentSequenceNumber(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) LogMetadata(org.apache.distributedlog.metadata.LogMetadata) Test(org.junit.Test)

Example 3 with LogMetadata

use of org.apache.distributedlog.metadata.LogMetadata in project bookkeeper by apache.

the class TestZKLogSegmentMetadataStore method testStoreMaxLogSegmentSequenceNumberOnNonExistentPath.

@Test(timeout = 60000)
public void testStoreMaxLogSegmentSequenceNumberOnNonExistentPath() throws Exception {
    Transaction<Object> updateTxn = lsmStore.transaction();
    Versioned<Long> value = new Versioned<Long>(999L, new LongVersion(10));
    final CompletableFuture<Version> result = new CompletableFuture<Version>();
    String nonExistentPath = rootZkPath + "/non-existent";
    LogMetadata metadata = mock(LogMetadata.class);
    when(metadata.getLogSegmentsPath()).thenReturn(nonExistentPath);
    lsmStore.storeMaxLogSegmentSequenceNumber(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);
        }
    });
    try {
        Utils.ioResult(updateTxn.execute());
        fail("Should fail on storing log segment sequence number if path doesn't exist");
    } catch (ZKException zke) {
        assertEquals(KeeperException.Code.NONODE, zke.getKeeperExceptionCode());
    }
    try {
        Utils.ioResult(result);
        fail("Should fail on storing log segment sequence number if path doesn't exist");
    } catch (ZKException ke) {
        assertEquals(KeeperException.Code.NONODE, ke.getKeeperExceptionCode());
    }
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) CompletableFuture(java.util.concurrent.CompletableFuture) ZKException(org.apache.distributedlog.exceptions.ZKException) Transaction(org.apache.distributedlog.util.Transaction) LongVersion(org.apache.bookkeeper.versioning.LongVersion) Version(org.apache.bookkeeper.versioning.Version) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogMetadata(org.apache.distributedlog.metadata.LogMetadata) Test(org.junit.Test)

Aggregations

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