Skip to content

Commit e5e2b22

Browse files
authored
IT: rm unrelevant, less logging in CI (#67)
Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
1 parent 0d230f0 commit e5e2b22

File tree

7 files changed

+333
-33
lines changed

7 files changed

+333
-33
lines changed

bmq-sdk/src/test/docker/config/clusters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "local",
55
"clusterAttributes": {
66
"isCSLModeEnabled": true,
7-
"isFSMWorkflow": false
7+
"isFSMWorkflow": true
88
},
99
"nodes": [
1010
{

bmq-sdk/src/test/java/com/bloomberg/bmq/impl/BrokerSessionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.bloomberg.bmq.impl;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
1920
import static org.junit.jupiter.api.Assertions.assertNotNull;
2021
import static org.junit.jupiter.api.Assertions.assertNull;
2122
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -185,7 +186,7 @@ public void verifySessionEvent(BrokerSessionEvent.Type type) {
185186

186187
logger.info("Verify session event: {}", event);
187188

188-
assertTrue(event instanceof BrokerSessionEvent);
189+
assertInstanceOf(BrokerSessionEvent.class, event);
189190

190191
assertEquals(type, ((BrokerSessionEvent) event).getEventType());
191192
}

bmq-sdk/src/test/java/com/bloomberg/bmq/it/SessionIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2122
import static org.junit.jupiter.api.Assertions.assertNotNull;
2223
import static org.junit.jupiter.api.Assertions.assertNull;
2324
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -494,9 +495,8 @@ private static void verifyQueueControlEvent(
494495
ResultCodes.GenericCode result,
495496
Queue queue) {
496497
assertNotNull(event);
497-
assertTrue(event instanceof QueueControlEvent);
498498

499-
QueueControlEvent queueControlEvent = (QueueControlEvent) event;
499+
QueueControlEvent queueControlEvent = assertInstanceOf(QueueControlEvent.class, event);
500500
assertEquals(queue, queueControlEvent.queue());
501501
assertEquals(eventType, queueControlEvent.type());
502502
assertEquals(result, queueControlEvent.result());

bmq-sdk/src/test/java/com/bloomberg/bmq/it/util/BmqBroker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ static BmqBroker createStoppedBroker(int port) throws IOException {
128128
}
129129

130130
static boolean dockerized() {
131-
return dockerImage() != null;
131+
return brokerDir() == null && dockerImage() != null;
132132
}
133133

134134
static String brokerDir() {
135135
return System.getProperty("it.brokerDir");
136136
}
137137

138138
static String dockerImage() {
139-
return System.getProperty("it.dockerImage");
139+
return System.getProperty("it.dockerImage", "bmq-broker-java-it");
140140
}
141141
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
* Copyright 2026 Bloomberg Finance L.P.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.bloomberg.bmq.it.util;
17+
18+
import com.google.gson.Gson;
19+
import com.google.gson.GsonBuilder;
20+
import com.google.gson.JsonObject;
21+
import java.io.IOException;
22+
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.nio.file.Paths;
26+
27+
/**
28+
* Loads and modifies BlazingMQ broker configuration for CI testing.
29+
*
30+
* <p>Supports modifying:
31+
*
32+
* <ul>
33+
* <li>bmqbrkrcfg.json: log file path, stats file path, TCP port
34+
* <li>clusters.json: node endpoint port, storage locations
35+
* </ul>
36+
*/
37+
public class BmqBrokerConfiguration {
38+
39+
private static final String BROKER_CONFIG_FILE = "bmqbrkrcfg.json";
40+
private static final String CLUSTERS_CONFIG_FILE = "clusters.json";
41+
private static final String DOMAINS_DIR = "domains";
42+
43+
private final Gson gson = new Gson();
44+
private final Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
45+
46+
private final Path configPath;
47+
private JsonObject brokerConfigJson;
48+
private JsonObject clustersConfigJson;
49+
50+
public static BmqBrokerConfiguration createFromDefaultPath() throws IOException {
51+
// Find config directory relative to this class's location
52+
Path classPath =
53+
Paths.get(
54+
BmqBrokerConfiguration.class
55+
.getProtectionDomain()
56+
.getCodeSource()
57+
.getLocation()
58+
.getPath());
59+
// Navigate from target/test-classes to src/test/docker/config
60+
Path configPath = classPath.getParent().getParent().resolve("src/test/docker/config");
61+
return new BmqBrokerConfiguration(configPath);
62+
}
63+
64+
public static BmqBrokerConfiguration createFromPath(Path configPath) throws IOException {
65+
return new BmqBrokerConfiguration(configPath);
66+
}
67+
68+
private BmqBrokerConfiguration(Path configPath) throws IOException {
69+
this.configPath = configPath;
70+
71+
Path brokerConfigPath = configPath.resolve(BROKER_CONFIG_FILE);
72+
brokerConfigJson =
73+
gson.fromJson(
74+
new String(Files.readAllBytes(brokerConfigPath), StandardCharsets.UTF_8),
75+
JsonObject.class);
76+
77+
Path clustersConfigPath = configPath.resolve(CLUSTERS_CONFIG_FILE);
78+
clustersConfigJson =
79+
gson.fromJson(
80+
new String(Files.readAllBytes(clustersConfigPath), StandardCharsets.UTF_8),
81+
JsonObject.class);
82+
}
83+
84+
// ==================== bmqbrkrcfg.json accessors ====================
85+
86+
/** taskConfig/logController/fileName */
87+
public String getLogFileName() {
88+
return brokerConfigJson
89+
.getAsJsonObject("taskConfig")
90+
.getAsJsonObject("logController")
91+
.get("fileName")
92+
.getAsString();
93+
}
94+
95+
public void setLogFileName(String fileName) {
96+
brokerConfigJson
97+
.getAsJsonObject("taskConfig")
98+
.getAsJsonObject("logController")
99+
.addProperty("fileName", fileName);
100+
}
101+
102+
/** appConfig/stats/printer/file */
103+
public String getStatsFile() {
104+
return brokerConfigJson
105+
.getAsJsonObject("appConfig")
106+
.getAsJsonObject("stats")
107+
.getAsJsonObject("printer")
108+
.get("file")
109+
.getAsString();
110+
}
111+
112+
public void setStatsFile(String file) {
113+
brokerConfigJson
114+
.getAsJsonObject("appConfig")
115+
.getAsJsonObject("stats")
116+
.getAsJsonObject("printer")
117+
.addProperty("file", file);
118+
}
119+
120+
/** appConfig/networkInterfaces/tcpInterface/port */
121+
public int getTcpPort() {
122+
return brokerConfigJson
123+
.getAsJsonObject("appConfig")
124+
.getAsJsonObject("networkInterfaces")
125+
.getAsJsonObject("tcpInterface")
126+
.get("port")
127+
.getAsInt();
128+
}
129+
130+
public void setTcpPort(int port) {
131+
brokerConfigJson
132+
.getAsJsonObject("appConfig")
133+
.getAsJsonObject("networkInterfaces")
134+
.getAsJsonObject("tcpInterface")
135+
.addProperty("port", port);
136+
}
137+
138+
// ==================== clusters.json accessors ====================
139+
140+
private JsonObject getFirstCluster() {
141+
return clustersConfigJson.getAsJsonArray("myClusters").get(0).getAsJsonObject();
142+
}
143+
144+
private JsonObject getFirstNode() {
145+
return getFirstCluster().getAsJsonArray("nodes").get(0).getAsJsonObject();
146+
}
147+
148+
/** myClusters[0]/nodes[0]/transport/tcp/endpoint */
149+
public String getNodeEndpoint() {
150+
return getFirstNode()
151+
.getAsJsonObject("transport")
152+
.getAsJsonObject("tcp")
153+
.get("endpoint")
154+
.getAsString();
155+
}
156+
157+
public void setNodeEndpoint(String endpoint) {
158+
getFirstNode()
159+
.getAsJsonObject("transport")
160+
.getAsJsonObject("tcp")
161+
.addProperty("endpoint", endpoint);
162+
}
163+
164+
/** Updates the port in the node endpoint (tcp://localhost:PORT) */
165+
public void setNodeEndpointPort(int port) {
166+
String endpoint = getNodeEndpoint();
167+
String newEndpoint = endpoint.replaceFirst(":\\d+$", ":" + port);
168+
setNodeEndpoint(newEndpoint);
169+
}
170+
171+
/** myClusters[0]/partitionConfig/location */
172+
public String getPartitionLocation() {
173+
return getFirstCluster().getAsJsonObject("partitionConfig").get("location").getAsString();
174+
}
175+
176+
public void setPartitionLocation(String location) {
177+
getFirstCluster().getAsJsonObject("partitionConfig").addProperty("location", location);
178+
}
179+
180+
/** myClusters[0]/partitionConfig/archiveLocation */
181+
public String getArchiveLocation() {
182+
return getFirstCluster()
183+
.getAsJsonObject("partitionConfig")
184+
.get("archiveLocation")
185+
.getAsString();
186+
}
187+
188+
public void setArchiveLocation(String location) {
189+
getFirstCluster()
190+
.getAsJsonObject("partitionConfig")
191+
.addProperty("archiveLocation", location);
192+
}
193+
194+
// ==================== Save ====================
195+
196+
/**
197+
* Saves configuration files to the specified directory, including domains.
198+
*
199+
* @param outputPath directory to save bmqbrkrcfg.json, clusters.json, and domains/
200+
*/
201+
public void saveTo(Path outputPath) throws IOException {
202+
Files.createDirectories(outputPath);
203+
204+
Files.write(
205+
outputPath.resolve(BROKER_CONFIG_FILE),
206+
prettyGson.toJson(brokerConfigJson).getBytes(StandardCharsets.UTF_8));
207+
208+
Files.write(
209+
outputPath.resolve(CLUSTERS_CONFIG_FILE),
210+
prettyGson.toJson(clustersConfigJson).getBytes(StandardCharsets.UTF_8));
211+
212+
// Copy domains directory
213+
Path srcDomains = configPath.resolve(DOMAINS_DIR);
214+
if (Files.isDirectory(srcDomains)) {
215+
Path destDomains = outputPath.resolve(DOMAINS_DIR);
216+
Files.createDirectories(destDomains);
217+
Files.list(srcDomains)
218+
.filter(p -> p.toString().endsWith(".json"))
219+
.forEach(
220+
src -> {
221+
try {
222+
Files.copy(src, destDomains.resolve(src.getFileName()));
223+
} catch (IOException e) {
224+
throw new RuntimeException("Failed to copy domain: " + src, e);
225+
}
226+
});
227+
}
228+
}
229+
}

bmq-sdk/src/test/java/com/bloomberg/bmq/it/util/BmqBrokerContainer.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.bloomberg.bmq.impl.infr.util.Argument;
2020
import com.github.dockerjava.api.DockerClient;
2121
import com.github.dockerjava.api.async.ResultCallback;
22+
import com.github.dockerjava.api.command.InspectContainerResponse;
2223
import com.github.dockerjava.api.model.Bind;
2324
import com.github.dockerjava.api.model.Frame;
2425
import com.github.dockerjava.api.model.HostConfig;
@@ -50,6 +51,8 @@ public class BmqBrokerContainer implements BmqBroker {
5051
private static final String CONTAINER_TMP_LOGS = "/tmp/logs";
5152
private static final String IMAGE_NAME = "bmq-broker-java-it";
5253
private static final String OUTPUT_FILENAME = "output.log";
54+
private static final long MAX_CONTAINER_WAIT_TIME_MS = 5000;
55+
private static final long CONTAINER_HEALTH_CHECK_DT_MS = 100;
5356

5457
private final SessionOptions sessionOptions;
5558
private final DockerClient client;
@@ -182,16 +185,32 @@ private BmqBrokerContainer(
182185

183186
@Override
184187
public void start() {
185-
logger.info("Start '{}' container", containerName);
188+
logger.info("Starting container '{}'...", containerName);
186189
client.startContainerCmd(containerId).exec();
187190

188191
try {
189-
Thread.sleep(5000);
192+
for (long totalTimeMs = 0;
193+
totalTimeMs < MAX_CONTAINER_WAIT_TIME_MS;
194+
totalTimeMs += CONTAINER_HEALTH_CHECK_DT_MS) {
195+
Thread.sleep(CONTAINER_HEALTH_CHECK_DT_MS);
196+
197+
InspectContainerResponse resp = client.inspectContainerCmd(containerId).exec();
198+
if (!resp.getState().getRunning()) {
199+
logger.error(
200+
"Container '{}' is not running, status = '{}'",
201+
containerId,
202+
resp.getState().getStatus());
203+
throw new RuntimeException(
204+
String.format("Failed to start container '{}'", containerId));
205+
}
206+
}
190207
} catch (InterruptedException e) {
191208
Thread.currentThread().interrupt();
192209
return;
193210
}
194211

212+
logger.info("Container '{}' is running", containerId);
213+
195214
// For BlazingMQ broker running in container default tier should be the 'lcl-{guest
196215
// hostname}'
197216
defaultTier = "lcl-" + getHostname();

0 commit comments

Comments
 (0)