Search in sources :

Example 11 with TestStatsProvider

use of org.apache.bookkeeper.test.TestStatsProvider in project herddb by diennea.

the class RetryOnLeaderChangedTest method testSwitchLeaderAndAuthTimeout.

@Test
public void testSwitchLeaderAndAuthTimeout() throws Exception {
    TestStatsProvider statsProvider = new TestStatsProvider();
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
    ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
    final AtomicBoolean suspendProcessing = new AtomicBoolean(false);
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        try (Server server_2 = new Server(serverconfig_2) {

            @Override
            protected ServerSideConnectionPeer buildPeer(Channel channel) {
                return new ServerSideConnectionPeer(channel, this) {

                    @Override
                    public void requestReceived(Pdu message, Channel channel) {
                        if (suspendProcessing.get()) {
                            LOG.log(Level.INFO, "dropping message type " + message.type + " id " + message.messageId);
                            message.close();
                            return;
                        }
                        super.requestReceived(message, channel);
                    }
                };
            }
        }) {
            server_2.start();
            TestUtils.execute(server_1.getManager(), "CREATE TABLESPACE 'ttt','leader:" + server_2.getNodeId() + "','expectedreplicacount:2'", Collections.emptyList());
            // wait for server_2 to wake up
            for (int i = 0; i < 40; i++) {
                TableSpaceManager tableSpaceManager2 = server_2.getManager().getTableSpaceManager("ttt");
                if (tableSpaceManager2 != null && tableSpaceManager2.isLeader()) {
                    break;
                }
                Thread.sleep(500);
            }
            assertTrue(server_2.getManager().getTableSpaceManager("ttt") != null && server_2.getManager().getTableSpaceManager("ttt").isLeader());
            // wait for server_1 to announce as follower
            waitClusterStatus(server_1.getManager(), server_1.getNodeId(), "follower");
            ClientConfiguration clientConfiguration = new ClientConfiguration();
            clientConfiguration.set(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_CLUSTER);
            clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
            clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
            clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
            clientConfiguration.set(ClientConfiguration.PROPERTY_MAX_CONNECTIONS_PER_SERVER, 2);
            clientConfiguration.set(ClientConfiguration.PROPERTY_TIMEOUT, 2000);
            StatsLogger logger = statsProvider.getStatsLogger("ds");
            try (HDBClient client1 = new HDBClient(clientConfiguration, logger) {

                @Override
                public HDBConnection openConnection() {
                    HDBConnection con = new VisibleRouteHDBConnection(this);
                    registerConnection(con);
                    return con;
                }
            }) {
                try (VisibleRouteHDBConnection connection = (VisibleRouteHDBConnection) client1.openConnection()) {
                    // create table and insert data
                    connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE ttt.t1(k1 int primary key, n1 int)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                    connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(1,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                    assertEquals("server2", connection.getRouteToTableSpace("ttt").getNodeId());
                    // change leader
                    switchLeader(server_1.getNodeId(), server_2.getNodeId(), server_1.getManager());
                    try (VisibleRouteHDBConnection connection2 = (VisibleRouteHDBConnection) client1.openConnection()) {
                        // connection routing still point to old leader (now follower)
                        assertEquals("server2", connection2.getRouteToTableSpace("ttt").getNodeId());
                        // suspend server_2 authentication
                        suspendProcessing.set(true);
                        // attempt an insert with old routing. Suspended autentication generates a timeout
                        // and routing will be reevaluated
                        assertEquals(1, connection2.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(2,2)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList()).updateCount);
                        // right routing to current master
                        assertEquals("server1", connection2.getRouteToTableSpace("ttt").getNodeId());
                        suspendProcessing.set(false);
                    }
                }
            }
        }
    }
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) Pdu(herddb.proto.Pdu) ServerSideConnectionPeer(herddb.server.ServerSideConnectionPeer) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) Server(herddb.server.Server) ServerConfiguration(herddb.server.ServerConfiguration) Channel(herddb.network.Channel) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HDBConnection(herddb.client.HDBConnection) HDBClient(herddb.client.HDBClient) TableSpaceManager(herddb.core.TableSpaceManager) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 12 with TestStatsProvider

use of org.apache.bookkeeper.test.TestStatsProvider in project bookkeeper by apache.

the class TestLedgerDirsManager method setUp.

@Before
public void setUp() throws Exception {
    PowerMockito.mockStatic(Executors.class);
    File tmpDir = createTempDir("bkTest", ".dir");
    curDir = Bookie.getCurrentDirectory(tmpDir);
    Bookie.checkDirectoryStructure(curDir);
    conf = TestBKConfiguration.newServerConfiguration();
    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    conf.setDiskLowWaterMarkUsageThreshold(conf.getDiskUsageThreshold());
    conf.setDiskCheckInterval(diskCheckInterval);
    conf.setIsForceGCAllowWhenNoSpace(true);
    executor = PowerMockito.mock(ScheduledExecutorService.class);
    executorController = new MockExecutorController().controlScheduleAtFixedRate(executor, 10);
    PowerMockito.when(Executors.newSingleThreadScheduledExecutor(any())).thenReturn(executor);
    mockDiskChecker = new MockDiskChecker(threshold, warnThreshold);
    statsProvider = new TestStatsProvider();
    statsLogger = statsProvider.getStatsLogger("test");
    dirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()), statsLogger);
    ledgerMonitor = new LedgerDirsMonitor(conf, mockDiskChecker, dirsManager);
    ledgerMonitor.init();
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) DiskChecker(org.apache.bookkeeper.util.DiskChecker) File(java.io.File) Before(org.junit.Before)

Example 13 with TestStatsProvider

use of org.apache.bookkeeper.test.TestStatsProvider in project bookkeeper by apache.

the class BookieJournalForceTest method testAckBeforeSyncWithJournalBufferedEntriesThreshold.

@Test
public void testAckBeforeSyncWithJournalBufferedEntriesThreshold() throws Exception {
    File journalDir = tempDir.newFolder();
    Bookie.checkDirectoryStructure(Bookie.getCurrentDirectory(journalDir));
    final int journalBufferedEntriesThreshold = 10;
    // sending a burst of entries, more than journalBufferedEntriesThreshold
    final int numEntries = journalBufferedEntriesThreshold + 50;
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setJournalDirName(journalDir.getPath()).setJournalBufferedEntriesThreshold(journalBufferedEntriesThreshold).setZkServers(null);
    JournalChannel jc = spy(new JournalChannel(journalDir, 1));
    whenNew(JournalChannel.class).withAnyArguments().thenReturn(jc);
    LedgerDirsManager ledgerDirsManager = mock(LedgerDirsManager.class);
    Journal journal = new Journal(0, journalDir, conf, ledgerDirsManager);
    // machinery to suspend ForceWriteThread
    CountDownLatch forceWriteThreadSuspendedLatch = new CountDownLatch(1);
    enableForceWriteThreadSuspension(forceWriteThreadSuspendedLatch, journal);
    TestStatsProvider testStatsProvider = new TestStatsProvider();
    Counter flushMaxOutstandingBytesCounter = testStatsProvider.getStatsLogger("test").getCounter("flushMaxOutstandingBytesCounter");
    Whitebox.setInternalState(journal, "flushMaxOutstandingBytesCounter", flushMaxOutstandingBytesCounter);
    journal.start();
    LogMark lastLogMarkBeforeWrite = journal.getLastLogMark().markLog().getCurMark();
    CountDownLatch latch = new CountDownLatch(numEntries);
    long ledgerId = 1;
    for (long entryId = 0; entryId < numEntries; entryId++) {
        journal.logAddEntry(ledgerId, entryId, DATA, true, /* ackBeforeSync */
        new WriteCallback() {

            @Override
            public void writeComplete(int rc, long ledgerId, long entryId, BookieSocketAddress addr, Object ctx) {
                latch.countDown();
            }
        }, null);
    }
    // logAddEntry should complete even if ForceWriteThread is suspended
    latch.await(20, TimeUnit.SECONDS);
    // in constructor of JournalChannel we are calling forceWrite(true) but it is not tracked by PowerMock
    // because the 'spy' is applied only on return from the constructor
    verify(jc, times(0)).forceWrite(true);
    // anyway we are never calling forceWrite
    verify(jc, times(0)).forceWrite(false);
    // verify that log marker did not advance
    LastLogMark lastLogMarkAfterForceWrite = journal.getLastLogMark();
    assertEquals(0, lastLogMarkAfterForceWrite.getCurMark().compare(lastLogMarkBeforeWrite));
    // let the forceWriteThread exit
    forceWriteThreadSuspendedLatch.countDown();
    assertTrue(flushMaxOutstandingBytesCounter.get() > 1);
    journal.shutdown();
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) LastLogMark(org.apache.bookkeeper.bookie.Journal.LastLogMark) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) WriteCallback(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback) LastLogMark(org.apache.bookkeeper.bookie.Journal.LastLogMark) CountDownLatch(java.util.concurrent.CountDownLatch) Counter(org.apache.bookkeeper.stats.Counter) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with TestStatsProvider

use of org.apache.bookkeeper.test.TestStatsProvider in project herddb by diennea.

the class ExpectedReplicaCountTest method testDisklessClusterReplication.

@Test
public void testDisklessClusterReplication() throws Exception {
    TestStatsProvider statsProvider = new TestStatsProvider();
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_DISKLESSCLUSTER);
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        TestUtils.execute(server_1.getManager(), "CREATE TABLESPACE 'ttt','leader:" + server_1.getNodeId() + "','expectedreplicacount:2'", Collections.emptyList());
        // perform some writes
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.set(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_CLUSTER);
        clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
        clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
        clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
        StatsLogger logger = statsProvider.getStatsLogger("ds");
        try (HDBClient client1 = new HDBClient(clientConfiguration, logger)) {
            try (HDBConnection connection = client1.openConnection()) {
                // create table and insert data
                connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE ttt.t1(k1 int primary key, n1 int)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(1,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(2,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(3,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                // flush data pages to BK
                server_1.getManager().checkpoint();
                Set<Long> initialLedgers = new HashSet<>();
                // verify that every ledger has ensemble size 2
                try (BookKeeper bk = createBookKeeper()) {
                    BookKeeperAdmin admin = new BookKeeperAdmin(bk);
                    for (long lId : admin.listLedgers()) {
                        LedgerMetadata md = bk.getLedgerManager().readLedgerMetadata(lId).get().getValue();
                        if ("ttt".equals(new String(md.getCustomMetadata().get("tablespaceuuid"), StandardCharsets.UTF_8))) {
                            assertEquals(2, md.getEnsembleSize());
                            assertEquals(2, md.getWriteQuorumSize());
                            assertEquals(2, md.getAckQuorumSize());
                            initialLedgers.add(lId);
                        }
                    }
                }
                BookkeeperCommitLog log = (BookkeeperCommitLog) server_1.getManager().getTableSpaceManager("ttt").getLog();
                final long currentLedgerId = log.getWriter().getLedgerId();
                // downsize to expectedreplicacount = 1
                TestUtils.execute(server_1.getManager(), "ALTER TABLESPACE 'ttt','leader:" + server_1.getNodeId() + "','expectedreplicacount:1'", Collections.emptyList());
                // the TableSpaceManager will roll a new ledger
                herddb.utils.TestUtils.waitForCondition(() -> {
                    if (log.getWriter() == null) {
                        return false;
                    }
                    long newLedgerId = log.getWriter().getLedgerId();
                    return newLedgerId != currentLedgerId;
                }, herddb.utils.TestUtils.NOOP, 100);
                // write some other record
                connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(4,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                // flush data pages
                server_1.getManager().checkpoint();
                // verify that every ledger has ensemble size 2 or 1
                try (BookKeeper bk = createBookKeeper()) {
                    BookKeeperAdmin admin = new BookKeeperAdmin(bk);
                    for (long lId : admin.listLedgers()) {
                        LedgerMetadata md = bk.getLedgerManager().readLedgerMetadata(lId).get().getValue();
                        if ("ttt".equals(new String(md.getCustomMetadata().get("tablespaceuuid"), StandardCharsets.UTF_8))) {
                            if (initialLedgers.contains(lId)) {
                                assertEquals(2, md.getEnsembleSize());
                                assertEquals(2, md.getWriteQuorumSize());
                                assertEquals(2, md.getAckQuorumSize());
                            } else {
                                assertEquals(1, md.getEnsembleSize());
                                assertEquals(1, md.getWriteQuorumSize());
                                assertEquals(1, md.getAckQuorumSize());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) Server(herddb.server.Server) ServerConfiguration(herddb.server.ServerConfiguration) BookKeeper(org.apache.bookkeeper.client.BookKeeper) HDBConnection(herddb.client.HDBConnection) HDBClient(herddb.client.HDBClient) LedgerMetadata(org.apache.bookkeeper.client.api.LedgerMetadata) ClientConfiguration(herddb.client.ClientConfiguration) BookKeeperAdmin(org.apache.bookkeeper.client.BookKeeperAdmin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with TestStatsProvider

use of org.apache.bookkeeper.test.TestStatsProvider in project herddb by diennea.

the class RetryOnLeaderChangedTest method test.

@Test
public void test() throws Exception {
    TestStatsProvider statsProvider = new TestStatsProvider();
    ServerConfiguration serverconfig_1 = newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
    ServerConfiguration serverconfig_2 = serverconfig_1.copy().set(ServerConfiguration.PROPERTY_NODEID, "server2").set(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().toPath().toAbsolutePath());
    try (Server server_1 = new Server(serverconfig_1)) {
        server_1.start();
        server_1.waitForStandaloneBoot();
        try (Server server_2 = new Server(serverconfig_2)) {
            server_2.start();
            TestUtils.execute(server_1.getManager(), "CREATE TABLESPACE 'ttt','leader:" + server_2.getNodeId() + "','expectedreplicacount:2'", Collections.emptyList());
            // wait for server_2 to wake up
            for (int i = 0; i < 40; i++) {
                TableSpaceManager tableSpaceManager2 = server_2.getManager().getTableSpaceManager("ttt");
                if (tableSpaceManager2 != null && tableSpaceManager2.isLeader()) {
                    break;
                }
                Thread.sleep(500);
            }
            assertTrue(server_2.getManager().getTableSpaceManager("ttt") != null && server_2.getManager().getTableSpaceManager("ttt").isLeader());
            // wait for server_1 to announce as follower
            waitClusterStatus(server_1.getManager(), server_1.getNodeId(), "follower");
            ClientConfiguration clientConfiguration = new ClientConfiguration();
            clientConfiguration.set(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_CLUSTER);
            clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
            clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
            clientConfiguration.set(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
            StatsLogger logger = statsProvider.getStatsLogger("ds");
            try (HDBClient client1 = new HDBClient(clientConfiguration, logger)) {
                try (HDBConnection connection = client1.openConnection()) {
                    // create table and insert data
                    connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE ttt.t1(k1 int primary key, n1 int)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                    connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(1,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                    connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(2,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                    connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO ttt.t1(k1,n1) values(3,1)", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList());
                    // use client2, so that it opens a connection to current leader
                    try (ScanResultSet scan = connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM ttt.t1", false, Collections.emptyList(), TransactionContext.NOTRANSACTION_ID, 0, 0, true)) {
                        assertEquals(3, scan.consume().size());
                    }
                    // change leader
                    switchLeader(server_1.getNodeId(), server_2.getNodeId(), server_1.getManager());
                    // perform operation
                    try (ScanResultSet scan = connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM ttt.t1", false, Collections.emptyList(), TransactionContext.NOTRANSACTION_ID, 0, 0, true)) {
                        assertEquals(3, scan.consume().size());
                    }
                    // check the client handled "not leader error"
                    assertEquals(1, logger.scope("hdbclient").getCounter("leaderChangedErrors").get().intValue());
                    // change leader
                    switchLeader(server_2.getNodeId(), server_1.getNodeId(), server_1.getManager());
                    // perform operation
                    GetResult get = connection.executeGet(TableSpace.DEFAULT, "SELECT * FROM ttt.t1 where k1=1", TransactionContext.NOTRANSACTION_ID, false, Collections.emptyList());
                    assertTrue(get.isFound());
                    // check the client handled "not leader error"
                    assertEquals(2, logger.scope("hdbclient").getCounter("leaderChangedErrors").get().intValue());
                    // change leader
                    switchLeader(server_1.getNodeId(), server_2.getNodeId(), server_1.getManager());
                    // perform operation
                    assertEquals(1, connection.executeUpdate(TableSpace.DEFAULT, "UPDATE ttt.t1 set n1=3 where k1=1", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList()).updateCount);
                    // check the client handled "not leader error"
                    assertEquals(3, logger.scope("hdbclient").getCounter("leaderChangedErrors").get().intValue());
                    // change leader
                    switchLeader(server_2.getNodeId(), server_1.getNodeId(), server_1.getManager());
                    // perform operation
                    assertEquals(1, connection.executeUpdateAsync(TableSpace.DEFAULT, "UPDATE ttt.t1 set n1=3 where k1=1", TransactionContext.NOTRANSACTION_ID, false, false, Collections.emptyList()).get().updateCount);
                    // check the client handled "not leader error"
                    assertEquals(4, logger.scope("hdbclient").getCounter("leaderChangedErrors").get().intValue());
                    // change leader
                    switchLeader(server_1.getNodeId(), server_2.getNodeId(), server_1.getManager());
                    // perform operation
                    assertEquals(1, connection.executeUpdates(TableSpace.DEFAULT, "UPDATE ttt.t1 set n1=3 where k1=1", TransactionContext.NOTRANSACTION_ID, false, false, Arrays.asList(Collections.emptyList())).get(0).updateCount);
                    // check the client handled "not leader error"
                    assertEquals(5, logger.scope("hdbclient").getCounter("leaderChangedErrors").get().intValue());
                    // change leader
                    switchLeader(server_2.getNodeId(), server_1.getNodeId(), server_1.getManager());
                    // perform operation
                    assertEquals(1, connection.executeUpdatesAsync(TableSpace.DEFAULT, "UPDATE ttt.t1 set n1=3 where k1=1", TransactionContext.NOTRANSACTION_ID, false, false, Arrays.asList(Collections.emptyList())).get().get(0).updateCount);
                    // check the client handled "not leader error"
                    assertEquals(6, logger.scope("hdbclient").getCounter("leaderChangedErrors").get().intValue());
                }
            }
        }
    }
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) HDBConnection(herddb.client.HDBConnection) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) GetResult(herddb.client.GetResult) ServerConfiguration(herddb.server.ServerConfiguration) TableSpaceManager(herddb.core.TableSpaceManager) ScanResultSet(herddb.client.ScanResultSet) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Aggregations

TestStatsProvider (org.apache.bookkeeper.test.TestStatsProvider)20 Test (org.junit.Test)16 CommitLog (herddb.log.CommitLog)6 LogEntry (herddb.log.LogEntry)6 LogSequenceNumber (herddb.log.LogSequenceNumber)6 Server (herddb.server.Server)6 ServerConfiguration (herddb.server.ServerConfiguration)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ClientConfiguration (herddb.client.ClientConfiguration)5 HDBClient (herddb.client.HDBClient)5 HDBConnection (herddb.client.HDBConnection)5 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)5 TableSpaceManager (herddb.core.TableSpaceManager)3 File (java.io.File)3 IOException (java.io.IOException)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)3 ScanResultSet (herddb.client.ScanResultSet)2 CommitLogResult (herddb.log.CommitLogResult)2 InetSocketAddress (java.net.InetSocketAddress)2 HashSet (java.util.HashSet)2