Skip to content

Commit

Permalink
test hserver support using file as metastore
Browse files Browse the repository at this point in the history
  • Loading branch information
Time Hoo committed Nov 28, 2022
1 parent b2aaa59 commit 6b5455d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/src/test/java/io/hstream/testing/BasicExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BasicExtension implements BeforeEachCallback, AfterEachCallback {

private static final Logger logger = LoggerFactory.getLogger(BasicExtension.class);
private Path dataDir;
private Path metadataDir;
private GenericContainer<?> zk;
private GenericContainer<?> rq;
private GenericContainer<?> hstore;
Expand All @@ -28,6 +29,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
printBeginFlag(context);

dataDir = Files.createTempDirectory("hstream");
metadataDir = Files.createTempDirectory("hstream-meta");

zk = makeZooKeeper();
zk.start();
Expand All @@ -49,7 +51,8 @@ public void beforeEach(ExtensionContext context) throws Exception {
options.port = hServerPort;
options.internalPort = hServerInternalPort;
options.metaHost = zkHost;
hserver = makeHServer(options, hServerAddress + ":" + hServerInternalPort, dataDir);
hserver =
makeHServer(options, hServerAddress + ":" + hServerInternalPort, dataDir, metadataDir);
hserver.start();
Thread.sleep(1000);
Object testInstance = context.getRequiredTestInstance();
Expand Down
11 changes: 10 additions & 1 deletion app/src/test/java/io/hstream/testing/ClusterExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ClusterExtension implements BeforeEachCallback, AfterEachCallback {
private final List<String> hServerInnerUrls = new ArrayList<>(CLUSTER_SIZE);
private String seedNodes;
private Path dataDir;

private Path metadataDir;
private GenericContainer<?> zk;
private GenericContainer<?> rq;
private GenericContainer<?> hstore;
Expand All @@ -43,6 +45,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
printBeginFlag(context);

dataDir = Files.createTempDirectory("hstream");
metadataDir = Files.createTempDirectory("hstream-meta");

TestUtils.SecurityOptions securityOptions = makeSecurityOptions(context.getTags());

Expand Down Expand Up @@ -76,7 +79,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
hServerInnerUrls.add(hServerAddress + ":" + hServerInnerPort);
}
seedNodes = hServerInnerUrls.stream().reduce((url1, url2) -> url1 + "," + url2).get();
hServers.addAll(bootstrapHServerCluster(hserverConfs, seedNodes, dataDir));
hServers.addAll(bootstrapHServerCluster(hserverConfs, seedNodes, dataDir, metadataDir));
hServers.stream().forEach(h -> logger.info(h.getLogs()));
Thread.sleep(3000);

Expand Down Expand Up @@ -115,6 +118,12 @@ public void beforeEach(ExtensionContext context) throws Exception {
.getClass()
.getMethod("setDataDir", Path.class)
.invoke(testInstance, dataDir));
silence(
() ->
testInstance
.getClass()
.getMethod("setMetadataDir", Path.class)
.invoke(testInstance, metadataDir));
silence(
() ->
testInstance
Expand Down
11 changes: 8 additions & 3 deletions app/src/test/java/io/hstream/testing/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ private static String getHStreamMetaStorePreference(String metaHost) {
} else if (hstreamMetaStore.equalsIgnoreCase("RQLITE")) {
logger.info("HSTREAM_META_STORE specified RQLITE as meta store");
return "rq://" + metaHost + ":4001";
} else if (hstreamMetaStore.equalsIgnoreCase("FILE")) {
logger.info("HSTREAM_META_STORE specified FILE as meta store");
return "file:///data/metastore/hstream";
} else {
throw new RuntimeException("Invalid HSTREAM_META_STORE env variable value");
}
Expand Down Expand Up @@ -184,10 +187,12 @@ public String toString() {
}

public static GenericContainer<?> makeHServer(
HServerCliOpts hserverConf, String seedNodes, Path dataDir) {
HServerCliOpts hserverConf, String seedNodes, Path dataDir, Path metadataDir) {
return new GenericContainer<>(getHStreamImageName())
.withNetworkMode("host")
.withFileSystemBind(dataDir.toAbsolutePath().toString(), "/data/hstore", BindMode.READ_ONLY)
.withFileSystemBind(
metadataDir.toAbsolutePath().toString(), "/data/metastore", BindMode.READ_WRITE)
.withFileSystemBind(hserverConf.securityOptions.dir, "/data/security", BindMode.READ_ONLY)
.withCommand(
"bash", "-c", " hstream-server" + hserverConf.toString() + " --seed-nodes " + seedNodes)
Expand Down Expand Up @@ -230,11 +235,11 @@ public String toString() {
}

public static List<GenericContainer<?>> bootstrapHServerCluster(
List<HServerCliOpts> hserverConfs, String seedNodes, Path dataDir)
List<HServerCliOpts> hserverConfs, String seedNodes, Path dataDir, Path metadataDir)
throws IOException, InterruptedException {
List<GenericContainer<?>> hServers = new ArrayList<>();
for (HServerCliOpts hserverConf : hserverConfs) {
var hServer = makeHServer(hserverConf, seedNodes, dataDir);
var hServer = makeHServer(hserverConf, seedNodes, dataDir, metadataDir);
hServers.add(hServer);
}
hServers.stream().parallel().forEach(GenericContainer::start);
Expand Down

0 comments on commit 6b5455d

Please sign in to comment.