Search in sources :

Example 76 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRackawareEnsemblePlacementPolicy method testReplaceBookieWithEnoughBookiesInSameRackAsEnsemble.

@Test
public void testReplaceBookieWithEnoughBookiesInSameRackAsEnsemble() throws Exception {
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.1", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.4", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/r2");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/r3");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    // replace node under r2
    Set<BookieSocketAddress> ensembleBookies = new HashSet<BookieSocketAddress>();
    ensembleBookies.add(addr2);
    ensembleBookies.add(addr4);
    BookieSocketAddress replacedBookie = repp.replaceBookie(1, 1, 1, null, ensembleBookies, addr4, new HashSet<>());
    assertEquals(addr1, replacedBookie);
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 77 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRackawareEnsemblePlacementPolicy method testReplaceBookieWithEnoughBookiesInSameRack.

@Test
public void testReplaceBookieWithEnoughBookiesInSameRack() throws Exception {
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/default-region/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/default-region/r2");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/default-region/r3");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    // replace node under r2
    BookieSocketAddress replacedBookie = repp.replaceBookie(1, 1, 1, null, new HashSet<>(), addr2, new HashSet<>());
    assertEquals(addr3, replacedBookie);
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 78 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRackawareEnsemblePlacementPolicy method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    StaticDNSResolver.reset();
    StaticDNSResolver.addNodeToRack(InetAddress.getLocalHost().getHostAddress(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack("127.0.0.1", NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack("localhost", NetworkTopology.DEFAULT_REGION_AND_RACK);
    LOG.info("Set up static DNS Resolver.");
    conf.setProperty(REPP_DNS_RESOLVER_CLASS, StaticDNSResolver.class.getName());
    addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_REGION + "/rack1");
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), NetworkTopology.DEFAULT_REGION + "/rack2");
    ensemble.add(addr1);
    ensemble.add(addr2);
    ensemble.add(addr3);
    ensemble.add(addr4);
    writeSet = writeSetFromValues(0, 1, 2, 3);
    timer = new HashedWheelTimer(new ThreadFactoryBuilder().setNameFormat("TestTimer-%d").build(), conf.getTimeoutTimerTickDurationMs(), TimeUnit.MILLISECONDS, conf.getTimeoutTimerNumTicks());
    repp = new RackawareEnsemblePlacementPolicy();
    repp.initialize(conf, Optional.<DNSToSwitchMapping>empty(), timer, DISABLE_ALL, NullStatsLogger.INSTANCE);
    repp.withDefaultRack(NetworkTopology.DEFAULT_REGION_AND_RACK);
}
Also used : StaticDNSResolver(org.apache.bookkeeper.util.StaticDNSResolver) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) HashedWheelTimer(io.netty.util.HashedWheelTimer)

Example 79 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRackawareEnsemblePlacementPolicy method testReplaceBookieWithEnoughBookiesInDifferentRack.

@Test
public void testReplaceBookieWithEnoughBookiesInDifferentRack() throws Exception {
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/default-region/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/default-region/r3");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/default-region/r4");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    // replace node under r2
    Set<BookieSocketAddress> excludedAddrs = new HashSet<BookieSocketAddress>();
    excludedAddrs.add(addr1);
    BookieSocketAddress replacedBookie = repp.replaceBookie(1, 1, 1, null, new HashSet<>(), addr2, excludedAddrs);
    assertFalse(addr1.equals(replacedBookie));
    assertTrue(addr3.equals(replacedBookie) || addr4.equals(replacedBookie));
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 80 with BookieSocketAddress

use of org.apache.bookkeeper.net.BookieSocketAddress in project bookkeeper by apache.

the class TestRackawareEnsemblePlacementPolicy method testRemoveBookieFromCluster.

/**
 * Test for BOOKKEEPER-633.
 */
@Test
public void testRemoveBookieFromCluster() {
    BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
    BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
    BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);
    BookieSocketAddress addr4 = new BookieSocketAddress("127.0.0.5", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getHostName(), NetworkTopology.DEFAULT_REGION_AND_RACK);
    StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/default-region/r2");
    StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/default-region/r2");
    StaticDNSResolver.addNodeToRack(addr4.getHostName(), "/default-region/r3");
    // Update cluster
    Set<BookieSocketAddress> addrs = new HashSet<BookieSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
    addrs.remove(addr1);
    repp.onClusterChanged(addrs, new HashSet<BookieSocketAddress>());
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)254 Test (org.junit.Test)140 HashSet (java.util.HashSet)67 CountDownLatch (java.util.concurrent.CountDownLatch)42 ArrayList (java.util.ArrayList)40 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)38 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)37 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)29 HashMap (java.util.HashMap)28 Map (java.util.Map)24 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)23 IOException (java.io.IOException)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 BookieServer (org.apache.bookkeeper.proto.BookieServer)14 WriteCallback (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback)13 Set (java.util.Set)11 ByteBuf (io.netty.buffer.ByteBuf)10 ByteBuffer (java.nio.ByteBuffer)10 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10