Search in sources :

Example 16 with Versioned

use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingVersion.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingVersion() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Test(org.junit.Test)

Example 17 with Versioned

use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingLockPath.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingLockPath() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)), new Versioned<byte[]>(ZKLogMetadataForWriter.intToBytes(ZKLogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Test(org.junit.Test)

Example 18 with Versioned

use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingMaxTxnId.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingMaxTxnId() throws Exception {
    String rootPath = "/test-missing-max-txn-id";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) Test(org.junit.Test)

Example 19 with Versioned

use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.

the class TestZKLogMetadataForWriterUtilFunctions method testProcessLogMetadatasMissingReadLockPath.

@SuppressWarnings("unchecked")
@Test(timeout = 60000, expected = UnexpectedException.class)
public void testProcessLogMetadatasMissingReadLockPath() throws Exception {
    String rootPath = "/test-missing-version";
    URI uri = DLMTestUtil.createDLMURI(2181, rootPath);
    String logName = "test-log";
    String logIdentifier = "<default>";
    List<Versioned<byte[]>> metadatas = Lists.newArrayList(new Versioned<byte[]>(null, null), new Versioned<byte[]>(null, null), new Versioned<byte[]>(DLUtils.serializeTransactionId(1L), new ZkVersion(1)), new Versioned<byte[]>(ZKLogMetadataForWriter.intToBytes(ZKLogMetadata.LAYOUT_VERSION), null), new Versioned<byte[]>(new byte[0], new ZkVersion(1)), new Versioned<byte[]>(null, null));
    ZKLogMetadataForWriter.processLogMetadatas(uri, logName, logIdentifier, metadatas, false);
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) URI(java.net.URI) ZkVersion(org.apache.bookkeeper.meta.ZkVersion) Test(org.junit.Test)

Example 20 with Versioned

use of org.apache.bookkeeper.versioning.Versioned in project distributedlog by twitter.

the class Utils method zkGetData.

/**
     * Retrieve data from zookeeper <code>path</code>.
     *
     * @param path
     *          zookeeper path to retrieve data
     * @param watch
     *          whether to watch the path
     * @return future representing the versioned value. null version or null value means path doesn't exist.
     */
public static Future<Versioned<byte[]>> zkGetData(ZooKeeper zk, String path, boolean watch) {
    final Promise<Versioned<byte[]>> promise = new Promise<Versioned<byte[]>>();
    zk.getData(path, watch, new AsyncCallback.DataCallback() {

        @Override
        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
            if (KeeperException.Code.OK.intValue() == rc) {
                if (null == stat) {
                    promise.setValue(new Versioned<byte[]>(null, null));
                } else {
                    promise.setValue(new Versioned<byte[]>(data, new ZkVersion(stat.getVersion())));
                }
            } else if (KeeperException.Code.NONODE.intValue() == rc) {
                promise.setValue(new Versioned<byte[]>(null, null));
            } else {
                promise.setException(KeeperException.create(KeeperException.Code.get(rc)));
            }
        }
    }, null);
    return promise;
}
Also used : Versioned(org.apache.bookkeeper.versioning.Versioned) AsyncCallback(org.apache.zookeeper.AsyncCallback) Promise(com.twitter.util.Promise) Stat(org.apache.zookeeper.data.Stat) ZkVersion(org.apache.bookkeeper.meta.ZkVersion)

Aggregations

Versioned (org.apache.bookkeeper.versioning.Versioned)22 ZkVersion (org.apache.bookkeeper.meta.ZkVersion)21 Test (org.junit.Test)17 Stat (org.apache.zookeeper.data.Stat)10 URI (java.net.URI)9 Promise (com.twitter.util.Promise)8 ZKException (com.twitter.distributedlog.exceptions.ZKException)7 Transaction (com.twitter.distributedlog.util.Transaction)6 Version (org.apache.bookkeeper.versioning.Version)6 KeeperException (org.apache.zookeeper.KeeperException)4 AsyncCallback (org.apache.zookeeper.AsyncCallback)3 ZKTransaction (com.twitter.distributedlog.zk.ZKTransaction)2 LedgerEntry (org.apache.bookkeeper.client.LedgerEntry)2 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)2 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)1 LogExistsException (com.twitter.distributedlog.exceptions.LogExistsException)1 LogNotFoundException (com.twitter.distributedlog.exceptions.LogNotFoundException)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1