From c7ce08122b7e4965aa1ebdba489af0366cec3105 Mon Sep 17 00:00:00 2001 From: Francesco Caliumi - Diennea Date: Fri, 10 Feb 2017 12:12:53 +0100 Subject: [PATCH] BOOKKEEPER-1001 Make LocalBookiesRegistry.isLocalBookie() public --- .../proto/LocalBookiesRegistry.java | 4 +- .../test/LocalBookiesRegistryTest.java | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LocalBookiesRegistryTest.java diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/LocalBookiesRegistry.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/LocalBookiesRegistry.java index 0dd2aa31f0a..738ee48c6d8 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/LocalBookiesRegistry.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/LocalBookiesRegistry.java @@ -26,7 +26,7 @@ /** * Local registry for embedded Bookies */ -class LocalBookiesRegistry { +public class LocalBookiesRegistry { private final static ConcurrentHashMap localBookiesRegistry = new ConcurrentHashMap<>(); @@ -39,7 +39,7 @@ static void unregisterLocalBookieAddress(BookieSocketAddress address) { localBookiesRegistry.remove(address); } } - static boolean isLocalBookie(BookieSocketAddress address) { + public static boolean isLocalBookie(BookieSocketAddress address) { return localBookiesRegistry.containsKey(address); } diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LocalBookiesRegistryTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LocalBookiesRegistryTest.java new file mode 100644 index 00000000000..25c5ff4d3a2 --- /dev/null +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/LocalBookiesRegistryTest.java @@ -0,0 +1,59 @@ +/** + * + * 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.test; + +import org.apache.bookkeeper.client.BookKeeper; +import org.apache.bookkeeper.conf.ServerConfiguration; +import org.apache.bookkeeper.proto.BookieServer; +import org.apache.bookkeeper.proto.LocalBookiesRegistry; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +/** + * Test the correctness and the availability outside of its package of LocalBookiesRegistryTest + */ +public class LocalBookiesRegistryTest extends BaseTestCase { + + @Override + protected ServerConfiguration newServerConfiguration() throws Exception { + return super + .newServerConfiguration() + .setDisableServerSocketBind(true) + .setEnableLocalTransport(true); + } + + BookKeeper.DigestType digestType; + + public LocalBookiesRegistryTest(BookKeeper.DigestType digestType) { + super(3); + this.digestType = digestType; + } + + @Test + public void testAccessibleLocalBookiesRegistry() throws Exception { + assertEquals(3,bs.size()); + for (BookieServer bk : bs) { + assertTrue(LocalBookiesRegistry.isLocalBookie(bk.getLocalAddress())); + } + } +}