Skip to content

Commit

Permalink
Prevent unit tests and E2E from using host ports 7181, 9000 and `…
Browse files Browse the repository at this point in the history
…9181`
  • Loading branch information
linghengqian committed Jul 27, 2024
1 parent 9bceb88 commit b9af231
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

class OneOffJobBootstrapTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), OneOffJobBootstrapTest.class.getSimpleName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
@ExtendWith(MockitoExtension.class)
class JobOperateAPIImplTest {

static final int DUMP_PORT = 9000;

private JobOperateAPI jobOperateAPI;

// TODO We should not use `Mock.Strictness.LENIENT` here, but the default. This is a flaw in the unit test design.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@ExtendWith(MockitoExtension.class)
class ZookeeperElectionServiceTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final String HOST_AND_PORT = "localhost:8899";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@

class ZookeeperRegistryCenterExecuteInLeaderTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterExecuteInLeaderTest.class.getName());
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterExecuteInLeaderTest.class.getName());
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@

class ZookeeperRegistryCenterForAuthTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final String NAME_SPACE = ZookeeperRegistryCenterForAuthTest.class.getName();

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), NAME_SPACE);

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIGURATION.setDigest("digest:password");
ZOOKEEPER_CONFIGURATION.setSessionTimeoutMilliseconds(5000);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(5000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), NAME_SPACE);
zookeeperConfiguration.setDigest("digest:password");
zookeeperConfiguration.setSessionTimeoutMilliseconds(5000);
zookeeperConfiguration.setConnectionTimeoutMilliseconds(5000);
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zkRegCenter.init();
RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@

class ZookeeperRegistryCenterMiscellaneousTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterMiscellaneousTest.class.getName());
private static ZookeeperConfiguration zookeeperConfiguration;

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterMiscellaneousTest.class.getName());
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zkRegCenter.init();
zkRegCenter.addCacheData("/test");
}
Expand All @@ -64,7 +64,7 @@ void assertGetRawCache() {

@Test
void assertGetZkConfig() {
ZookeeperRegistryCenter zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
assertThat(zkRegCenter.getZkConfig(), is(ZOOKEEPER_CONFIGURATION));
ZookeeperRegistryCenter zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
assertThat(zkRegCenter.getZkConfig(), is(zookeeperConfiguration));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@

class ZookeeperRegistryCenterModifyTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterModifyTest.class.getName());
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterModifyTest.class.getName());
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@

class ZookeeperRegistryCenterQueryWithCacheTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithCacheTest.class.getName());
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithCacheTest.class.getName());
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
zkRegCenter.addCacheData("/test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@

class ZookeeperRegistryCenterQueryWithoutCacheTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithoutCacheTest.class.getName());
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithoutCacheTest.class.getName());
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zkRegCenter.init();
RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
zkRegCenter.addCacheData("/other");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@

class ZookeeperRegistryCenterTransactionTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterTransactionTest.class.getName());
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterTransactionTest.class.getName());
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@

class ZookeeperRegistryCenterWatchTest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181);

private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterWatchTest.class.getName());
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static ZookeeperRegistryCenter zkRegCenter;

@BeforeAll
static void setUp() {
EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterWatchTest.class.getName());
zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@Getter(AccessLevel.PROTECTED)
public abstract class BaseAnnotationE2ETest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@Getter(AccessLevel.PROTECTED)
public abstract class BaseE2ETest {

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

public abstract class BaseSnapshotServiceE2ETest {

static final int DUMP_PORT = 9000;
static final int DUMP_PORT = -1;

private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181);
private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer();

private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public final class EmbedTestingServer {

private static final Object INIT_LOCK = new Object();

private final int port;

/**
* Start embed zookeeper server.
*/
Expand All @@ -64,7 +62,7 @@ public void start() {

private void start0() {
try {
testingServer = new TestingServer(port, true);
testingServer = new TestingServer();
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
Expand Down Expand Up @@ -132,6 +130,6 @@ private boolean isIgnoredException(final Throwable cause) {
* @return connection string
*/
public String getConnectionString() {
return "localhost:" + port;
return testingServer.getConnectString();
}
}

0 comments on commit b9af231

Please sign in to comment.