Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURATOR-594: TestingZooKeeperMain isn't setting tickTime, if configured #383

Merged
merged 1 commit into from May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,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);
}
}