use of org.apache.zookeeper.server.metric.SimpleCounter in project zookeeper by apache.
the class NettyServerCnxnFactoryTest method testOutstandingHandshakeLimit.
/*
* In this test we are flooding the server with SSL connections, and expecting that not
* all the connection will succeed at once. Some of the connections should be closed,
* as there is a maximum number of parallel SSL handshake the server is willing to do
* for security reasons.
*/
@Test
public void testOutstandingHandshakeLimit() throws Exception {
// setting up SSL params, but disable some debug logs
x509Util = SSLAuthTest.setUpSecure();
System.clearProperty("javax.net.debug");
// starting a single server (it will be closed in the tearDown)
setUpWithServerId(1);
// initializing the statistics
SimpleCounter tlsHandshakeExceeded = (SimpleCounter) ServerMetrics.getMetrics().TLS_HANDSHAKE_EXCEEDED;
tlsHandshakeExceeded.reset();
assertEquals(tlsHandshakeExceeded.get(), 0);
// setting the HandshakeLimit to 3, so only 3 SSL handshakes can happen in parallel
NettyServerCnxnFactory factory = (NettyServerCnxnFactory) serverFactory;
factory.setSecure(true);
factory.setOutstandingHandshakeLimit(3);
// starting the threads that will try to connect to the server
// we will have 3 threads, each of them establishing 3 connections
int threadNum = 3;
int cnxnPerThread = 3;
int cnxnLimit = threadNum * cnxnPerThread;
AtomicInteger cnxnCreated = new AtomicInteger(0);
CountDownLatch latch = new CountDownLatch(1);
Thread[] cnxnWorker = new Thread[threadNum];
for (int i = 0; i < cnxnWorker.length; i++) {
cnxnWorker[i] = new ClientConnectionGenerator(i, cnxnPerThread, cnxnCreated, cnxnLimit, latch, zooKeeperClients);
cnxnWorker[i].start();
}
// we might need to wait potentially for a longer time for all the connection to get established,
// as the ZooKeeper Server will close some of the connections and the clients will have to re-try
boolean allConnectionsCreatedInTime = latch.await(30, TimeUnit.SECONDS);
int actualConnections = cnxnCreated.get();
LOG.info("created {} connections", actualConnections);
if (!allConnectionsCreatedInTime) {
fail(String.format("Only %d out of %d connections created!", actualConnections, cnxnLimit));
}
// Assert the server refused some of the connections because the handshake limit was reached
// (throttling should be greater than 0)
long handshakeThrottledNum = tlsHandshakeExceeded.get();
LOG.info("TLS_HANDSHAKE_EXCEEDED: {}", handshakeThrottledNum);
assertThat("The number of handshake throttled should be " + "greater than 0", handshakeThrottledNum, Matchers.greaterThan(0L));
// Assert there is no outstanding handshake anymore, all the clients connected in the end
int outstandingHandshakeNum = factory.getOutstandingHandshakeNum();
LOG.info("outstanding handshake is {}", outstandingHandshakeNum);
assertThat("The outstanding handshake number should be 0 " + "after all cnxns established", outstandingHandshakeNum, Matchers.is(0));
}
use of org.apache.zookeeper.server.metric.SimpleCounter in project zookeeper by apache.
the class TxnLogDigestTest method digestFromTxnLogsMatchesTree.
/**
* Check that the digest stored in the txn matches the digest calculated
* from DataTree.
*/
@Test
public void digestFromTxnLogsMatchesTree() throws Exception {
// reset the mismatch metrics
SimpleCounter digestMistachesCount = (SimpleCounter) ServerMetrics.getMetrics().DIGEST_MISMATCHES_COUNT;
digestMistachesCount.reset();
// trigger some write ops
performOperations(createClient(), "/digestFromTxnLogsMatchesTree");
// make sure there is no digest mismatch
assertEquals(0, digestMistachesCount.get());
// verify that the digest is wrote to disk with txn
TxnDigest lastDigest = getLastTxnLogDigest();
assertNotNull(lastDigest);
assertEquals(server.getZKDatabase().getDataTree().getTreeDigest(), lastDigest.getTreeDigest());
}
use of org.apache.zookeeper.server.metric.SimpleCounter in project zookeeper by apache.
the class ServerMetricsTest method testSimpleCounter.
@Test
public void testSimpleCounter() {
SimpleCounter metric = new SimpleCounter("test");
testSimpleCounter(metric, 0);
testSimpleCounter(metric, 1);
for (int i = 0; i < RANDOM_TRIALS; ++i) {
testSimpleCounter(metric, RANDOM_SIZE);
}
}
use of org.apache.zookeeper.server.metric.SimpleCounter in project zookeeper by apache.
the class TxnLogDigestTest method testTxnMissing.
/**
* Simulate the scenario where txn is missing, and make sure the
* digest code can catch this issue.
*/
@Test
public void testTxnMissing() throws Exception {
// updated MockedFileTxnLog to skip append txn on specific txn
MockedFileTxnLog.skipAppendZxid = 3;
// trigger some write operations
performOperations(createClient(), "/testTxnMissing");
// restart server to load the corrupted txn file
SimpleCounter digestMistachesCount = (SimpleCounter) ServerMetrics.getMetrics().DIGEST_MISMATCHES_COUNT;
digestMistachesCount.reset();
restartServerWithDigestFlag(true);
// check that digest mismatch is reported
assertThat("mismtach should be reported", digestMistachesCount.get(), greaterThan(0L));
// restart server with digest disabled
digestMistachesCount.reset();
restartServerWithDigestFlag(false);
// check that no digest mismatch is reported
assertEquals(0, digestMistachesCount.get());
}
use of org.apache.zookeeper.server.metric.SimpleCounter in project zookeeper by apache.
the class TxnLogDigestTest method checkTxnCompatibleWithAndWithoutDigest.
/**
* Test the compatible when enable/disable digest:
*
* * check that txns which were written with digest can be read when
* digest is disabled
* * check that txns which were written without digest can be read
* when digest is enabled.
*/
@Test
public void checkTxnCompatibleWithAndWithoutDigest() throws Exception {
// 1. start server with digest disabled
restartServerWithDigestFlag(false);
// trigger some write ops
Map<String, String> expectedNodes = performOperations(createClient(), "/p1");
// reset the mismatch metrics
SimpleCounter digestMistachesCount = (SimpleCounter) ServerMetrics.getMetrics().DIGEST_MISMATCHES_COUNT;
digestMistachesCount.reset();
// 2. restart server with digest enabled
restartServerWithDigestFlag(true);
// make sure the data wrote when digest was disabled can be
// successfully read
checkNodes(expectedNodes);
Map<String, String> expectedNodes1 = performOperations(createClient(), "/p2");
// make sure there is no digest mismatch
assertEquals(0, digestMistachesCount.get());
// 3. disable the digest again and make sure everything is fine
restartServerWithDigestFlag(false);
checkNodes(expectedNodes);
checkNodes(expectedNodes1);
}
Aggregations