bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject [1/2] bookkeeper git commit: BOOKKEEPER-959: ClientAuthProvider and BookieAuthProvider Public API used Protobuf Shaded classes
Date Tue, 31 Jan 2017 01:14:30 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 26b09abb4 -> 13d668f22


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/13d668f2/bookkeeper-server/src/test/java/org/apache/bookkeeper/auth/TestAuth.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/auth/TestAuth.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/auth/TestAuth.java
index a57bfe9..f499ad3 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/auth/TestAuth.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/auth/TestAuth.java
@@ -20,10 +20,9 @@
  */
 package org.apache.bookkeeper.auth;
 
-import java.net.InetSocketAddress;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Enumeration;
-import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -36,18 +35,17 @@ import org.apache.bookkeeper.conf.ClientConfiguration;
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.proto.BookieServer;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
-import org.apache.bookkeeper.proto.BookkeeperProtocol.AuthMessage;
-import org.apache.bookkeeper.proto.TestDataFormats;
 import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
-import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.*;
 
 import org.junit.Test;
+import org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException;
+import org.apache.bookkeeper.client.ClientConnectionPeer;
+import org.apache.bookkeeper.bookie.BookieConnectionPeer;
 
-import com.google.protobuf.ExtensionRegistry;
 
 public class TestAuth extends BookKeeperClusterTestCase {
     static final Logger LOG = LoggerFactory.getLogger(TestAuth.class);
@@ -55,6 +53,10 @@ public class TestAuth extends BookKeeperClusterTestCase {
     private static final byte[] PASSWD = "testPasswd".getBytes();
     private static final byte[] ENTRY = "TestEntry".getBytes();
 
+    private static final byte[] SUCCESS_RESPONSE = {1};
+    private static final byte[] FAILURE_RESPONSE = {2};
+    private static final byte[] PAYLOAD_MESSAGE = {3};
+
     public TestAuth() {
         super(0); // start them later when auth providers are configured
     }
@@ -127,6 +129,44 @@ public class TestAuth extends BookKeeperClusterTestCase {
         assertEquals("Should have entry", 1, entryCount(ledgerId.get(), bookieConf, clientConf));
     }
     
+    @Test(timeout=30000)
+    public void testCloseMethodCalledOnAuthProvider() throws Exception {
+        ServerConfiguration bookieConf = newServerConfiguration();
+        bookieConf.setBookieAuthProviderFactoryClass(
+                LogCloseCallsBookieAuthProviderFactory.class.getName());
+
+        ClientConfiguration clientConf = newClientConfiguration();
+        clientConf.setClientAuthProviderFactoryClass(
+                LogCloseCallsClientAuthProviderFactory.class.getName());
+
+        startAndStoreBookie(bookieConf);
+
+        AtomicLong ledgerId = new AtomicLong(-1);
+        connectAndWriteToBookie(clientConf, ledgerId); // should succeed
+
+        assertFalse(ledgerId.get() == -1);
+        assertEquals("Should have entry", 1, entryCount(ledgerId.get(), bookieConf, clientConf));
+
+        for (BookieServer bks : bs) {
+            bks.shutdown();
+        }
+
+        assertEquals(LogCloseCallsBookieAuthProviderFactory.initCountersOnConnections.get(),
+            LogCloseCallsBookieAuthProviderFactory.closeCountersOnConnections.get());
+        assertTrue(LogCloseCallsBookieAuthProviderFactory.initCountersOnConnections.get()
> 0);
+
+        assertEquals(1, LogCloseCallsBookieAuthProviderFactory.initCountersOnFactory.get());
+        assertEquals(1, LogCloseCallsBookieAuthProviderFactory.closeCountersOnFactory.get());
+
+        assertEquals(LogCloseCallsClientAuthProviderFactory.initCountersOnConnections.get(),
+            LogCloseCallsClientAuthProviderFactory.closeCountersOnConnections.get());
+        assertTrue(LogCloseCallsClientAuthProviderFactory.initCountersOnConnections.get()
> 0);
+
+        assertEquals(1, LogCloseCallsClientAuthProviderFactory.initCountersOnFactory.get());
+        assertEquals(1, LogCloseCallsClientAuthProviderFactory.closeCountersOnFactory.get());
+
+    }
+
     /**
      * Test that when the bookie provider sends a failure message
      * the client will not be able to write
@@ -354,6 +394,50 @@ public class TestAuth extends BookKeeperClusterTestCase {
         assertEquals("Shouldn't have entry", 0, entryCount(ledgerId.get(), bookieConf, clientConf));
     }
 
+    /**
+     * Client will try to perform authentication but bookies are not configured
+     */
+    @Test(timeout=30000)
+    public void testClientWithAuthAndBookieWithDisabledAuth() throws Exception {
+        ServerConfiguration bookieConf = newServerConfiguration();
+        assertNull(bookieConf.getBookieAuthProviderFactoryClass());
+
+        ClientConfiguration clientConf = newClientConfiguration();
+        clientConf.setClientAuthProviderFactoryClass(
+                SendUntilCompleteClientAuthProviderFactory.class.getName());
+
+        startAndStoreBookie(bookieConf);
+
+        AtomicLong ledgerId = new AtomicLong(-1);
+        connectAndWriteToBookie(clientConf, ledgerId); // should succeed
+
+        assertFalse(ledgerId.get() == -1);
+        assertEquals("Should have entry", 1, entryCount(ledgerId.get(), bookieConf, clientConf));
+    }
+
+    /**
+     * The plugin will drop the connection from the bookie side
+     */
+    @Test(timeout=30000)
+    public void testDropConnectionFromBookieAuthPlugin() throws Exception {
+        ServerConfiguration bookieConf = newServerConfiguration();
+        bookieConf.setBookieAuthProviderFactoryClass(
+                DropConnectionBookieAuthProviderFactory.class.getName());
+
+        ClientConfiguration clientConf = newClientConfiguration();
+        clientConf.setClientAuthProviderFactoryClass(
+                SendUntilCompleteClientAuthProviderFactory.class.getName());
+
+        startAndStoreBookie(bookieConf);
+
+        AtomicLong ledgerId = new AtomicLong(-1);
+        try {
+            connectAndWriteToBookie(clientConf, ledgerId); // should fail
+            fail();
+        } catch (BKNotEnoughBookiesException error){
+        }
+    }
+
     BookieServer startAndStoreBookie(ServerConfiguration conf) throws Exception {
         bsConfs.add(conf);
         BookieServer s = startBookie(conf);
@@ -369,24 +453,84 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                    addr.setAuthorizedId(new BookKeeperPrincipal("test-principal"));
+                    cb.operationComplete(BKException.Code.OK, AuthToken.wrap(SUCCESS_RESPONSE));
+                    completeCb.operationComplete(BKException.Code.OK, null);
+                }
+            };
+        }
+    }
+
+    private static class LogCloseCallsBookieAuthProviderFactory implements BookieAuthProvider.Factory
{
 
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
-                    builder.setExtension(TestDataFormats.messageType, 
-                            TestDataFormats.AuthMessageType.SUCCESS_RESPONSE);
+        private static AtomicInteger closeCountersOnFactory = new AtomicInteger();
+        private static AtomicInteger closeCountersOnConnections = new AtomicInteger();
+        private static AtomicInteger initCountersOnFactory = new AtomicInteger();
+        private static AtomicInteger initCountersOnConnections = new AtomicInteger();
+
+        @Override
+        public void init(ServerConfiguration conf) throws IOException {
+            initCountersOnFactory.incrementAndGet();
+        }
+
+        @Override
+        public void close() {
+            closeCountersOnFactory.incrementAndGet();
+        }
 
-                    cb.operationComplete(BKException.Code.OK, builder.build());
+        @Override
+        public BookieAuthProvider newProvider(BookieConnectionPeer connection, AuthCallbacks.GenericCallback<Void>
completeCb) {
+            return new BookieAuthProvider() {
+
+                {
                     completeCb.operationComplete(BKException.Code.OK, null);
+                    initCountersOnConnections.incrementAndGet();
+                }
+
+                @Override
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+
+                }
+
+                @Override
+                public void close() {
+                    closeCountersOnConnections.incrementAndGet();
+                }
+            };
+        }
+
+        @Override
+        public String getPluginName() {
+            return TEST_AUTH_PROVIDER_PLUGIN_NAME;
+        }
+
+    }
+
+    public static class DropConnectionBookieAuthProviderFactory
+        implements BookieAuthProvider.Factory {
+        @Override
+        public String getPluginName() {
+            return TEST_AUTH_PROVIDER_PLUGIN_NAME;
+        }
+
+        @Override
+        public void init(ServerConfiguration conf) {
+        }
+
+        @Override
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
+            return new BookieAuthProvider() {
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                    addr.disconnect();
                 }
             };
         }
@@ -400,22 +544,16 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
-                    builder.setExtension(TestDataFormats.messageType, 
-                            TestDataFormats.AuthMessageType.FAILURE_RESPONSE);
-
-                    cb.operationComplete(BKException.Code.OK, builder.build());
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                    addr.setAuthorizedId(new BookKeeperPrincipal("test-principal"));
+                    cb.operationComplete(BKException.Code.OK, AuthToken.wrap(FAILURE_RESPONSE));
                     completeCb.operationComplete(
                             BKException.Code.UnauthorizedAccessException, null);
                 }
@@ -423,47 +561,79 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
     }
 
+    private static class LogCloseCallsClientAuthProviderFactory implements ClientAuthProvider.Factory
{
+
+        private static AtomicInteger initCountersOnFactory = new AtomicInteger();
+        private static AtomicInteger initCountersOnConnections = new AtomicInteger();
+        private static AtomicInteger closeCountersOnFactory = new AtomicInteger();
+        private static AtomicInteger closeCountersOnConnections = new AtomicInteger();
+
+        @Override
+        public void init(ClientConfiguration conf) throws IOException {
+            initCountersOnFactory.incrementAndGet();
+        }
+
+        @Override
+        public ClientAuthProvider newProvider(ClientConnectionPeer connection, AuthCallbacks.GenericCallback<Void>
completeCb) {
+            return new ClientAuthProvider() {
+
+                @Override
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                }
+
+                @Override
+                public void close() {
+                    closeCountersOnConnections.incrementAndGet();
+                }
+
+                @Override
+                public void init(AuthCallbacks.GenericCallback<AuthToken> cb) {
+                    initCountersOnConnections.incrementAndGet();
+                    completeCb.operationComplete(BKException.Code.OK, null);
+                }
+            };
+        }
+
+        @Override
+        public String getPluginName() {
+            return TEST_AUTH_PROVIDER_PLUGIN_NAME;
+        }
+
+        @Override
+        public void close() {
+            closeCountersOnFactory.incrementAndGet();
+        }
+
+    }
+
     private static class SendUntilCompleteClientAuthProviderFactory
         implements ClientAuthProvider.Factory {
-        
+
         @Override
         public String getPluginName() {
             return TEST_AUTH_PROVIDER_PLUGIN_NAME;
         }
 
         @Override
-        public void init(ClientConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ClientConfiguration conf) {
         }
 
         @Override
-        public ClientAuthProvider newProvider(InetSocketAddress addr,
-                final GenericCallback<Void> completeCb) {
-            AuthMessage.Builder builder
-                = AuthMessage.newBuilder()
-                .setAuthPluginName(getPluginName());
-            builder.setExtension(TestDataFormats.messageType, 
-                                 TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
-            final AuthMessage message = builder.build();
-
+        public ClientAuthProvider newProvider(ClientConnectionPeer addr,
+                final AuthCallbacks.GenericCallback<Void> completeCb) {
             return new ClientAuthProvider() {
-                public void init(GenericCallback<AuthMessage> cb) {
-                    cb.operationComplete(BKException.Code.OK, message);
+                public void init(AuthCallbacks.GenericCallback<AuthToken> cb) {
+                    cb.operationComplete(BKException.Code.OK, AuthToken.wrap(PAYLOAD_MESSAGE));
                 }
-
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-                    if (m.hasExtension(TestDataFormats.messageType)) {
-                        TestDataFormats.AuthMessageType type
-                            = m.getExtension(TestDataFormats.messageType);
-                        if (type == TestDataFormats.AuthMessageType.SUCCESS_RESPONSE) {
-                            completeCb.operationComplete(BKException.Code.OK, null);
-                        } else if (type == TestDataFormats.AuthMessageType.FAILURE_RESPONSE)
{
-                            completeCb.operationComplete(BKException.Code.UnauthorizedAccessException,
null);
-                        } else {
-                            cb.operationComplete(BKException.Code.OK, message);
-                        }
-                    } else {
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                    byte[] type = m.getData();
+                    if (Arrays.equals(type,SUCCESS_RESPONSE)) {
+                        addr.setAuthorizedId(new BookKeeperPrincipal("test-client-principal"));
+                        completeCb.operationComplete(BKException.Code.OK, null);
+                    } else if (Arrays.equals(type,FAILURE_RESPONSE)) {
                         completeCb.operationComplete(BKException.Code.UnauthorizedAccessException,
null);
+                    } else {
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(PAYLOAD_MESSAGE));
                     }
                 }
             };
@@ -480,29 +650,20 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
                     if (numMessages.incrementAndGet() == 3) {
-                        builder.setExtension(TestDataFormats.messageType, 
-                                TestDataFormats.AuthMessageType.SUCCESS_RESPONSE);
-
-                        cb.operationComplete(BKException.Code.OK, builder.build());
+                        addr.setAuthorizedId(new BookKeeperPrincipal("test-principal"));
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(SUCCESS_RESPONSE));
                         completeCb.operationComplete(BKException.Code.OK, null);
                     } else {
-                        builder.setExtension(TestDataFormats.messageType, 
-                                TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
-
-                        cb.operationComplete(BKException.Code.OK, builder.build());
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(PAYLOAD_MESSAGE));
                     }
                 }
             };
@@ -519,30 +680,21 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
                     if (numMessages.incrementAndGet() == 3) {
-                        builder.setExtension(TestDataFormats.messageType, 
-                                TestDataFormats.AuthMessageType.FAILURE_RESPONSE);
-
-                        cb.operationComplete(BKException.Code.OK, builder.build());
+                        addr.setAuthorizedId(new BookKeeperPrincipal("test-principal"));
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(FAILURE_RESPONSE));
                         completeCb.operationComplete(BKException.Code.UnauthorizedAccessException,
                                                      null);
                     } else {
-                        builder.setExtension(TestDataFormats.messageType, 
-                                TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
-
-                        cb.operationComplete(BKException.Code.OK, builder.build());
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(PAYLOAD_MESSAGE));
                     }
                 }
             };
@@ -559,25 +711,19 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
                     if (numMessages.incrementAndGet() == 3) {
                         throw new RuntimeException("Do bad things to the bookie");
                     } else {
-                        builder.setExtension(TestDataFormats.messageType, 
-                                TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
-
-                        cb.operationComplete(BKException.Code.OK, builder.build());
+                        addr.setAuthorizedId(new BookKeeperPrincipal("test-principal"));
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(PAYLOAD_MESSAGE));
                     }
                 }
             };
@@ -595,25 +741,18 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
                     if (numMessages.incrementAndGet() != 3) {
-                        builder.setExtension(TestDataFormats.messageType,
-                                TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
-                        cb.operationComplete(BKException.Code.OK, builder.build());
+                        cb.operationComplete(BKException.Code.OK, AuthToken.wrap(PAYLOAD_MESSAGE));
                         return;
                     }
-
                     crashType2bookieInstance.suspendProcessing();
                 }
             };
@@ -628,23 +767,15 @@ public class TestAuth extends BookKeeperClusterTestCase {
         }
 
         @Override
-        public void init(ServerConfiguration conf, ExtensionRegistry registry) {
-            TestDataFormats.registerAllExtensions(registry);
+        public void init(ServerConfiguration conf) {
         }
 
         @Override
-        public BookieAuthProvider newProvider(InetSocketAddress addr,
-                                              final GenericCallback<Void> completeCb)
{
+        public BookieAuthProvider newProvider(BookieConnectionPeer addr,
+                                              final AuthCallbacks.GenericCallback<Void>
completeCb) {
             return new BookieAuthProvider() {
-                public void process(AuthMessage m, GenericCallback<AuthMessage> cb)
{
-
-                    AuthMessage.Builder builder
-                        = AuthMessage.newBuilder()
-                        .setAuthPluginName(getPluginName());
-                    builder.setExtension(TestDataFormats.messageType, 
-                            TestDataFormats.AuthMessageType.FAILURE_RESPONSE);
-
-                    cb.operationComplete(BKException.Code.OK, builder.build());
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                    cb.operationComplete(BKException.Code.OK, AuthToken.wrap(FAILURE_RESPONSE));
                     completeCb.operationComplete(BKException.Code.OK, null);
                 }
             };

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/13d668f2/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBackwardCompatCMS42.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBackwardCompatCMS42.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBackwardCompatCMS42.java
index fe87ac9..0a9bdc4 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBackwardCompatCMS42.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestBackwardCompatCMS42.java
@@ -20,8 +20,8 @@
  */
 package org.apache.bookkeeper.proto;
 
+import com.google.protobuf.ByteString;
 import org.apache.bookkeeper.conf.ServerConfiguration;
-import org.apache.bookkeeper.proto.BookieProtocol;
 import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -32,8 +32,6 @@ import com.google.protobuf.ExtensionRegistry;
 import org.apache.bookkeeper.auth.ClientAuthProvider;
 import org.apache.bookkeeper.conf.ClientConfiguration;
 import org.apache.bookkeeper.net.BookieSocketAddress;
-import org.apache.bookkeeper.proto.PerChannelBookieClient;
-import org.apache.bookkeeper.proto.BookieServer;
 import org.apache.bookkeeper.util.OrderedSafeExecutor;
 import org.apache.bookkeeper.auth.TestAuth;
 import org.jboss.netty.bootstrap.ClientBootstrap;
@@ -59,6 +57,10 @@ import static org.junit.Assert.*;
 public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase {
     static final Logger LOG = LoggerFactory.getLogger(TestBackwardCompatCMS42.class);
 
+    private static final byte[] SUCCESS_RESPONSE = {1};
+    private static final byte[] FAILURE_RESPONSE = {2};
+    private static final byte[] PAYLOAD_MESSAGE = {3};
+
     ExtensionRegistry extRegistry = ExtensionRegistry.newInstance();
     ClientAuthProvider.Factory authProvider;
     ClientSocketChannelFactory channelFactory
@@ -69,10 +71,8 @@ public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase
{
 
     public TestBackwardCompatCMS42() throws Exception {
         super(0);
-
-        TestDataFormats.registerAllExtensions(extRegistry);
         authProvider = AuthProviderFactoryFactory.newClientAuthProviderFactory(
-                new ClientConfiguration(), extRegistry);
+                new ClientConfiguration());
     }
 
     @Test(timeout=60000)
@@ -84,8 +84,7 @@ public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase {
 
         AuthMessage.Builder builder = AuthMessage.newBuilder()
             .setAuthPluginName(TestAuth.TEST_AUTH_PROVIDER_PLUGIN_NAME);
-        builder.setExtension(TestDataFormats.messageType,
-                             TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
+        builder.setPayload(ByteString.copyFrom(PAYLOAD_MESSAGE));
         final AuthMessage authMessage = builder.build();
 
         CompatClient42 client = newCompatClient(bookie1.getLocalAddress());
@@ -107,8 +106,7 @@ public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase
{
 
         AuthMessage.Builder builder = AuthMessage.newBuilder()
             .setAuthPluginName(TestAuth.TEST_AUTH_PROVIDER_PLUGIN_NAME);
-        builder.setExtension(TestDataFormats.messageType,
-                             TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
+        builder.setPayload(ByteString.copyFrom(PAYLOAD_MESSAGE));
         final AuthMessage authMessage = builder.build();
         CompatClient42 client = newCompatClient(bookie1.getLocalAddress());
 
@@ -120,14 +118,14 @@ public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase
{
             AuthResponse authResponse = (AuthResponse)response;
             assertEquals("Should have succeeded",
                          response.getErrorCode(), BookieProtocol.EOK);
-            TestDataFormats.AuthMessageType type = authResponse.getAuthMessage()
-                .getExtension(TestDataFormats.messageType);
+            byte[] type = authResponse.getAuthMessage()
+                .getPayload().toByteArray();
             if (i == 2) {
-                assertEquals("Should succeed after 3",
-                             type, TestDataFormats.AuthMessageType.SUCCESS_RESPONSE);
+                assertArrayEquals("Should succeed after 3",
+                             type, SUCCESS_RESPONSE);
             } else {
-                assertEquals("Should be payload", type,
-                             TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
+                assertArrayEquals("Should be payload", type,
+                             PAYLOAD_MESSAGE);
             }
         }
     }
@@ -141,8 +139,7 @@ public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase
{
 
         AuthMessage.Builder builder = AuthMessage.newBuilder()
             .setAuthPluginName(TestAuth.TEST_AUTH_PROVIDER_PLUGIN_NAME);
-        builder.setExtension(TestDataFormats.messageType,
-                             TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
+        builder.setPayload(ByteString.copyFrom(PAYLOAD_MESSAGE));
         final AuthMessage authMessage = builder.build();
         CompatClient42 client = newCompatClient(bookie1.getLocalAddress());
 
@@ -154,14 +151,14 @@ public class TestBackwardCompatCMS42 extends BookKeeperClusterTestCase
{
             AuthResponse authResponse = (AuthResponse)response;
             assertEquals("Should have succeeded",
                          response.getErrorCode(), BookieProtocol.EOK);
-            TestDataFormats.AuthMessageType type = authResponse.getAuthMessage()
-                .getExtension(TestDataFormats.messageType);
+            byte[] type = authResponse.getAuthMessage()
+                .getPayload().toByteArray();
             if (i == 2) {
-                assertEquals("Should fail after 3",
-                             type, TestDataFormats.AuthMessageType.FAILURE_RESPONSE);
+                assertArrayEquals("Should fail after 3",
+                             type, FAILURE_RESPONSE);
             } else {
-                assertEquals("Should be payload", type,
-                             TestDataFormats.AuthMessageType.PAYLOAD_MESSAGE);
+                assertArrayEquals("Should be payload", type,
+                             PAYLOAD_MESSAGE);
             }
 
         }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/13d668f2/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestDataFormats.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestDataFormats.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestDataFormats.java
deleted file mode 100644
index 84e1a77..0000000
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestDataFormats.java
+++ /dev/null
@@ -1,149 +0,0 @@
-// Generated by the protocol buffer compiler.  DO NOT EDIT!
-// source: src/test/proto/TestDataFormats.proto
-
-package org.apache.bookkeeper.proto;
-
-public final class TestDataFormats {
-  private TestDataFormats() {}
-  public static void registerAllExtensions(
-      com.google.protobuf.ExtensionRegistry registry) {
-    registry.add(org.apache.bookkeeper.proto.TestDataFormats.messageType);
-  }
-  /**
-   * Protobuf enum {@code AuthMessageType}
-   */
-  public enum AuthMessageType
-      implements com.google.protobuf.ProtocolMessageEnum {
-    /**
-     * <code>SUCCESS_RESPONSE = 1;</code>
-     */
-    SUCCESS_RESPONSE(0, 1),
-    /**
-     * <code>FAILURE_RESPONSE = 2;</code>
-     */
-    FAILURE_RESPONSE(1, 2),
-    /**
-     * <code>PAYLOAD_MESSAGE = 3;</code>
-     */
-    PAYLOAD_MESSAGE(2, 3),
-    ;
-
-    /**
-     * <code>SUCCESS_RESPONSE = 1;</code>
-     */
-    public static final int SUCCESS_RESPONSE_VALUE = 1;
-    /**
-     * <code>FAILURE_RESPONSE = 2;</code>
-     */
-    public static final int FAILURE_RESPONSE_VALUE = 2;
-    /**
-     * <code>PAYLOAD_MESSAGE = 3;</code>
-     */
-    public static final int PAYLOAD_MESSAGE_VALUE = 3;
-
-
-    public final int getNumber() { return value; }
-
-    public static AuthMessageType valueOf(int value) {
-      switch (value) {
-        case 1: return SUCCESS_RESPONSE;
-        case 2: return FAILURE_RESPONSE;
-        case 3: return PAYLOAD_MESSAGE;
-        default: return null;
-      }
-    }
-
-    public static com.google.protobuf.Internal.EnumLiteMap<AuthMessageType>
-        internalGetValueMap() {
-      return internalValueMap;
-    }
-    private static com.google.protobuf.Internal.EnumLiteMap<AuthMessageType>
-        internalValueMap =
-          new com.google.protobuf.Internal.EnumLiteMap<AuthMessageType>() {
-            public AuthMessageType findValueByNumber(int number) {
-              return AuthMessageType.valueOf(number);
-            }
-          };
-
-    public final com.google.protobuf.Descriptors.EnumValueDescriptor
-        getValueDescriptor() {
-      return getDescriptor().getValues().get(index);
-    }
-    public final com.google.protobuf.Descriptors.EnumDescriptor
-        getDescriptorForType() {
-      return getDescriptor();
-    }
-    public static final com.google.protobuf.Descriptors.EnumDescriptor
-        getDescriptor() {
-      return org.apache.bookkeeper.proto.TestDataFormats.getDescriptor().getEnumTypes().get(0);
-    }
-
-    private static final AuthMessageType[] VALUES = values();
-
-    public static AuthMessageType valueOf(
-        com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
-      if (desc.getType() != getDescriptor()) {
-        throw new java.lang.IllegalArgumentException(
-          "EnumValueDescriptor is not for this type.");
-      }
-      return VALUES[desc.getIndex()];
-    }
-
-    private final int index;
-    private final int value;
-
-    private AuthMessageType(int index, int value) {
-      this.index = index;
-      this.value = value;
-    }
-
-    // @@protoc_insertion_point(enum_scope:AuthMessageType)
-  }
-
-  public static final int MESSAGETYPE_FIELD_NUMBER = 1000;
-  /**
-   * <code>extend .AuthMessage { ... }</code>
-   */
-  public static final
-    com.google.protobuf.GeneratedMessage.GeneratedExtension<
-      org.apache.bookkeeper.proto.BookkeeperProtocol.AuthMessage,
-      org.apache.bookkeeper.proto.TestDataFormats.AuthMessageType> messageType = com.google.protobuf.GeneratedMessage
-          .newFileScopedGeneratedExtension(
-        org.apache.bookkeeper.proto.TestDataFormats.AuthMessageType.class,
-        null);
-
-  public static com.google.protobuf.Descriptors.FileDescriptor
-      getDescriptor() {
-    return descriptor;
-  }
-  private static com.google.protobuf.Descriptors.FileDescriptor
-      descriptor;
-  static {
-    java.lang.String[] descriptorData = {
-      "\n$src/test/proto/TestDataFormats.proto\032\'" +
-      "src/main/proto/BookkeeperProtocol.proto*" +
-      "R\n\017AuthMessageType\022\024\n\020SUCCESS_RESPONSE\020\001" +
-      "\022\024\n\020FAILURE_RESPONSE\020\002\022\023\n\017PAYLOAD_MESSAG" +
-      "E\020\003:4\n\013messageType\022\014.AuthMessage\030\350\007 \001(\0162" +
-      "\020.AuthMessageTypeB\037\n\033org.apache.bookkeep" +
-      "er.protoH\001"
-    };
-    com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
-        new com.google.protobuf.Descriptors.FileDescriptor.    InternalDescriptorAssigner()
{
-          public com.google.protobuf.ExtensionRegistry assignDescriptors(
-              com.google.protobuf.Descriptors.FileDescriptor root) {
-            descriptor = root;
-            return null;
-          }
-        };
-    com.google.protobuf.Descriptors.FileDescriptor
-      .internalBuildGeneratedFileFrom(descriptorData,
-        new com.google.protobuf.Descriptors.FileDescriptor[] {
-          org.apache.bookkeeper.proto.BookkeeperProtocol.getDescriptor(),
-        }, assigner);
-    messageType.internalInit(descriptor.getExtensions().get(0));
-    org.apache.bookkeeper.proto.BookkeeperProtocol.getDescriptor();
-  }
-
-  // @@protoc_insertion_point(outer_class_scope)
-}

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/13d668f2/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestPerChannelBookieClient.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestPerChannelBookieClient.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestPerChannelBookieClient.java
index b43f5cd..2095b66 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestPerChannelBookieClient.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/proto/TestPerChannelBookieClient.java
@@ -65,7 +65,7 @@ public class TestPerChannelBookieClient extends BookKeeperClusterTestCase
{
     public TestPerChannelBookieClient() throws Exception {
         super(1);
         authProvider = AuthProviderFactoryFactory.newClientAuthProviderFactory(
-                new ClientConfiguration(), extRegistry);
+                new ClientConfiguration());
     }
 
 

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/13d668f2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuthAutoRecoveryTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuthAutoRecoveryTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuthAutoRecoveryTest.java
new file mode 100644
index 0000000..470aefe
--- /dev/null
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuthAutoRecoveryTest.java
@@ -0,0 +1,111 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.replication;
+
+import org.apache.bookkeeper.auth.AuthCallbacks;
+import org.apache.bookkeeper.auth.AuthToken;
+import org.apache.bookkeeper.auth.ClientAuthProvider;
+import org.apache.bookkeeper.client.BKException;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+
+
+import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.*;
+import org.apache.bookkeeper.client.ClientConnectionPeer;
+
+/**
+ * This test verifies the auditor bookie scenarios from the auth point-of-view
+ */
+public class AuthAutoRecoveryTest extends BookKeeperClusterTestCase {
+
+    private final static Logger LOG = LoggerFactory
+        .getLogger(AuthAutoRecoveryTest.class);
+
+    public static final String TEST_AUTH_PROVIDER_PLUGIN_NAME = "TestAuthProviderPlugin";
+
+    private static String clientSideRole;
+
+    private static class AuditorClientAuthInterceptorFactory
+        implements ClientAuthProvider.Factory {
+
+        @Override
+        public String getPluginName() {
+            return TEST_AUTH_PROVIDER_PLUGIN_NAME;
+        }
+
+        @Override
+        public void init(ClientConfiguration conf) {
+            clientSideRole = conf.getClientRole();
+        }
+
+        @Override
+        public ClientAuthProvider newProvider(ClientConnectionPeer addr,
+            final AuthCallbacks.GenericCallback<Void> completeCb) {
+            return new ClientAuthProvider() {
+                public void init(AuthCallbacks.GenericCallback<AuthToken> cb) {
+
+                    completeCb.operationComplete(BKException.Code.OK, null);
+                }
+
+                public void process(AuthToken m, AuthCallbacks.GenericCallback<AuthToken>
cb) {
+                }
+            };
+        }
+    }
+
+    protected ServerConfiguration newServerConfiguration() throws Exception {
+        ServerConfiguration conf = super.newServerConfiguration();
+        conf.setClientAuthProviderFactoryClass(AuditorClientAuthInterceptorFactory.class.getName());
+        return conf;
+    }
+
+    public AuthAutoRecoveryTest() {
+        super(6);
+    }
+
+    /*
+     * test the client role of the auditor
+     */
+    @Test(timeout = 60000)
+    public void testAuthClientRole() throws Exception {
+        ServerConfiguration config = bsConfs.get(0);
+        assertEquals(AuditorClientAuthInterceptorFactory.class.getName(), config.getClientAuthProviderFactoryClass());
+        AutoRecoveryMain main = new AutoRecoveryMain(config);
+        try {
+            main.start();
+            Thread.sleep(500);
+            assertTrue("AuditorElector should be running",
+                main.auditorElector.isRunning());
+            assertTrue("Replication worker should be running",
+                main.replicationWorker.isRunning());
+        } finally {
+            main.shutdown();
+        }
+        assertEquals(ClientConfiguration.CLIENT_ROLE_SYSTEM, clientSideRole);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/13d668f2/bookkeeper-server/src/test/proto/TestDataFormats.proto
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/proto/TestDataFormats.proto b/bookkeeper-server/src/test/proto/TestDataFormats.proto
deleted file mode 100644
index be149ed..0000000
--- a/bookkeeper-server/src/test/proto/TestDataFormats.proto
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-option java_package = "org.apache.bookkeeper.proto";
-option optimize_for = SPEED;
-
-import "src/main/proto/BookkeeperProtocol.proto";
-
-enum AuthMessageType {
-    SUCCESS_RESPONSE = 1;
-    FAILURE_RESPONSE = 2;
-    PAYLOAD_MESSAGE = 3;
-}
-
-/**
- *
- */
-extend AuthMessage {
-    optional AuthMessageType messageType = 1000;
-}


Mime
View raw message