Skip to content
Permalink
Browse files
CURATOR-594: TestingZooKeeperMain isn't setting tickTime, if configur…
…ed (#383)
  • Loading branch information
franz1981 committed May 26, 2021
1 parent 15a9f03 commit c26dd85fc3be8ac591c9d7daf69eedb4d7b45dbb
Showing 4 changed files with 67 additions and 0 deletions.
@@ -31,6 +31,10 @@ public class TestingServer implements Closeable
private final TestingZooKeeperServer testingZooKeeperServer;
private final InstanceSpec spec;

TestingZooKeeperServer getTestingZooKeeperServer() {
return testingZooKeeperServer;
}

/**
* Create the server using a random port
*
@@ -97,6 +97,10 @@ public void kill()
}
}

TestZooKeeperServer getZkServer() {
return zkServer;
}

@Override
public void runFromConfig(QuorumPeerConfig config) throws Exception
{
@@ -271,6 +275,8 @@ public TestZooKeeperServer(FileTxnSnapLog txnLog, ServerConfig config)
{
this.txnLog = txnLog;
this.setTxnLogFactory(txnLog);
// tickTime would affect min and max session timeout: should be set first
this.setTickTime(config.getTickTime());
this.setMinSessionTimeout(config.getMinSessionTimeout());
this.setMaxSessionTimeout(config.getMaxSessionTimeout());
}
@@ -40,6 +40,10 @@ public class TestingZooKeeperServer implements Closeable
private volatile ZooKeeperMainFace main;
private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);

ZooKeeperMainFace getMain() {
return main;
}

private enum State
{
LATENT, STARTED, STOPPED, CLOSED
@@ -0,0 +1,53 @@
/**
* 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.curator.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;

import org.apache.zookeeper.server.ZooKeeperServer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class TestTestingServer {

@TempDir
File zkTmpDir;

@Test
public void setCustomTickTimeTest() throws Exception {
final int defaultZkTickTime = ZooKeeperServer.DEFAULT_TICK_TIME;
final int customTickMs;
if (defaultZkTickTime > 0) {
customTickMs = defaultZkTickTime + (defaultZkTickTime == Integer.MAX_VALUE ? -1 : +1);
} else {
customTickMs = 100;
}
final InstanceSpec spec = new InstanceSpec(zkTmpDir, -1, -1, -1, true, -1, customTickMs, -1);
final int zkTickTime;
try (TestingServer testingServer = new TestingServer(spec, true)) {
TestingZooKeeperMain main = (TestingZooKeeperMain) testingServer.getTestingZooKeeperServer().getMain();
zkTickTime = main.getZkServer().getTickTime();
}
assertEquals(customTickMs, zkTickTime);
}
}

0 comments on commit c26dd85

Please sign in to comment.