Skip to content

Commit

Permalink
Fix failing tests of ZooKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperxpro committed Aug 27, 2023
1 parent 8db7ec0 commit 73d070a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.shieldblaze.expressgateway.common.ExpressGateway;
import org.apache.curator.test.InstanceSpec;
import org.apache.curator.test.TestingServer;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -58,29 +59,11 @@ void connectToZooKeeperUsingTLSTest() throws Exception {
File file = new File(classLoader.getResource("default").getFile());
String absolutePath = file.getAbsolutePath();

int randomUsablePort = InstanceSpec.getRandomPort();

Map<String, Object> customProperties = new HashMap<>();
customProperties.put("secureClientPort", String.valueOf(randomUsablePort));
customProperties.put("ssl.keyStore.location", absolutePath + File.separator + "KeyStore.jks");
customProperties.put("ssl.keyStore.password", "123456");
customProperties.put("ssl.trustStore.location", absolutePath + File.separator + "TrustStore.jks");
customProperties.put("ssl.trustStore.password", "123456");
customProperties.put("ssl.hostnameVerification", "false");
customProperties.put("serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory");

InstanceSpec instanceSpec = new InstanceSpec(null,
randomUsablePort,
-1,
-1,
true,
-1,
-1,
-1,
customProperties);
int securePort = InstanceSpec.getRandomPort();
InstanceSpec instanceSpec = instanceSpec(securePort, absolutePath);

try (TestingServer testingServer = new TestingServer(instanceSpec, true)) {
ExpressGateway.setInstance(forTest(new ExpressGateway.ZooKeeper(testingServer.getConnectString(),
ExpressGateway.setInstance(forTest(new ExpressGateway.ZooKeeper("127.0.0.1:" + securePort,
3,
100,
true,
Expand All @@ -101,4 +84,26 @@ void connectToZooKeeperUsingTLSTest() throws Exception {
System.clearProperty("zookeeper.ssl.trustStore.password");
}
}

@NotNull
private static InstanceSpec instanceSpec(int securePort, String absolutePath) {
Map<String, Object> customProperties = new HashMap<>();
customProperties.put("secureClientPort", String.valueOf(securePort));
customProperties.put("ssl.keyStore.location", absolutePath + File.separator + "KeyStore.jks");
customProperties.put("ssl.keyStore.password", "123456");
customProperties.put("ssl.trustStore.location", absolutePath + File.separator + "TrustStore.jks");
customProperties.put("ssl.trustStore.password", "123456");
customProperties.put("ssl.hostnameVerification", "false");
customProperties.put("serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory");

return new InstanceSpec(null,
InstanceSpec.getRandomPort(),
-1,
-1,
true,
-1,
-1,
-1,
customProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
package com.shieldblaze.expressgateway.common.zookeeper;

import com.shieldblaze.expressgateway.common.ExpressGateway;
import org.apache.curator.test.InstanceSpec;
import org.apache.curator.test.QuorumConfigBuilder;
import org.apache.curator.test.QuorumPeerConfigBuilder;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.ZooKeeperServerEmbeddedAdapter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static com.shieldblaze.expressgateway.common.zookeeper.Curator.getInstance;
import static com.shieldblaze.expressgateway.common.zookeeper.CuratorUtils.createNew;
import static com.shieldblaze.expressgateway.common.zookeeper.CuratorUtils.deleteData;
Expand Down
Loading

0 comments on commit 73d070a

Please sign in to comment.