Skip to content

Commit

Permalink
CURATOR-594: TestingZooKeeperMain isn't setting tickTime, if configured
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Apr 21, 2021
1 parent 15a9f03 commit 55b9b85
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
Expand Up @@ -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
*
Expand Down
Expand Up @@ -97,6 +97,10 @@ public void kill()
}
}

TestZooKeeperServer getZkServer() {
return zkServer;
}

@Override
public void runFromConfig(QuorumPeerConfig config) throws Exception
{
Expand Down Expand Up @@ -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());
}
Expand Down
Expand Up @@ -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
Expand Down
@@ -0,0 +1,51 @@
/**
* 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;

public class TestTestingServer {

@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(null, -1, -1, -1, true, -1, customTickMs, -1);
final int zkTickTime;
try (TestingServer testingServer = new TestingServer(spec, true)) {
final File tmpDir = testingServer.getTempDirectory();
tmpDir.deleteOnExit();
TestingZooKeeperMain main = (TestingZooKeeperMain) testingServer.getTestingZooKeeperServer().getMain();
zkTickTime = main.getZkServer().getTickTime();
}
assertEquals(customTickMs, zkTickTime);
}
}

0 comments on commit 55b9b85

Please sign in to comment.