Skip to content

Commit c9e7995

Browse files
committed
IT: use COUNTING allocator and check that broker container has started
Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
1 parent 9203baf commit c9e7995

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"taskConfig": {
3-
"allocatorType": "STACKTRACETEST",
3+
"allocatorType": "COUNTING",
44
"allocationLimit": 34359738368,
55
"logController": {
66
"fileName": "/var/local/bmq/logs/logs.%T.%p",

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class BmqBrokerContainer implements BmqBroker {
5353
private static final String OUTPUT_FILENAME = "output.log";
5454
private static final long MAX_CONTAINER_WAIT_TIME_MS = 5000;
5555
private static final long CONTAINER_HEALTH_CHECK_DT_MS = 100;
56+
private static final String BROKER_READY_MESSAGE = "Cluster (local) is available";
5657

5758
private final SessionOptions sessionOptions;
5859
private final DockerClient client;
@@ -194,22 +195,36 @@ public void start() {
194195
totalTimeMs += CONTAINER_HEALTH_CHECK_DT_MS) {
195196
Thread.sleep(CONTAINER_HEALTH_CHECK_DT_MS);
196197

198+
// Check if container is still running
197199
InspectContainerResponse resp = client.inspectContainerCmd(containerId).exec();
198200
if (!resp.getState().getRunning()) {
199201
logger.error(
200202
"Container '{}' is not running, status = '{}'",
201203
containerId,
202204
resp.getState().getStatus());
203205
throw new RuntimeException(
204-
String.format("Failed to start container '{}'", containerId));
206+
String.format("Failed to start container '%s'", containerId));
207+
}
208+
209+
// Check logs for broker readiness message
210+
if (isBrokerReady()) {
211+
logger.info("Container '{}' broker is ready", containerId);
212+
break;
213+
}
214+
215+
if (totalTimeMs + CONTAINER_HEALTH_CHECK_DT_MS >= MAX_CONTAINER_WAIT_TIME_MS) {
216+
throw new RuntimeException(
217+
String.format(
218+
"Timeout waiting for broker ready in container '%s'",
219+
containerId));
205220
}
206221
}
207222
} catch (InterruptedException e) {
208223
Thread.currentThread().interrupt();
209224
return;
210225
}
211226

212-
logger.info("Container '{}' is running", containerId);
227+
logger.info("Container '{}' broker is ready", containerId);
213228

214229
// For BlazingMQ broker running in container default tier should be the 'lcl-{guest
215230
// hostname}'
@@ -357,6 +372,29 @@ public void onNext(Frame item) {
357372
}
358373
}
359374

375+
private boolean isBrokerReady() {
376+
final boolean[] ready = {false};
377+
ResultCallback.Adapter<Frame> callback =
378+
new ResultCallback.Adapter<Frame>() {
379+
@Override
380+
public void onNext(Frame item) {
381+
if (item.toString().contains(BROKER_READY_MESSAGE)) {
382+
ready[0] = true;
383+
}
384+
}
385+
};
386+
try {
387+
client.logContainerCmd(containerId)
388+
.withStdOut(true)
389+
.withStdErr(true)
390+
.exec(callback)
391+
.awaitCompletion();
392+
} catch (InterruptedException e) {
393+
Thread.currentThread().interrupt();
394+
}
395+
return ready[0];
396+
}
397+
360398
private String getHostname() {
361399
// Get container hostname
362400
logger.info("Get '{}' container hostname", containerName);

0 commit comments

Comments
 (0)