use of org.apache.activemq.broker.Connection in project activemq-artemis by apache.
the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.
@Test
public void TestOptimizedDispatchCME() throws Exception {
final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
final ConnectionContext contextNotInTx = new ConnectionContext();
contextNotInTx.setConnection(new Connection() {
@Override
public void stop() throws Exception {
}
@Override
public void start() throws Exception {
}
@Override
public void updateClient(ConnectionControl control) {
}
@Override
public void serviceExceptionAsync(IOException e) {
}
@Override
public void serviceException(Throwable error) {
}
@Override
public Response service(Command command) {
return null;
}
@Override
public boolean isSlow() {
return false;
}
@Override
public boolean isNetworkConnection() {
return false;
}
@Override
public boolean isManageable() {
return false;
}
@Override
public boolean isFaultTolerantConnection() {
return false;
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isBlocked() {
return false;
}
@Override
public boolean isActive() {
return false;
}
@Override
public ConnectionStatistics getStatistics() {
return null;
}
@Override
public String getRemoteAddress() {
return null;
}
@Override
public int getDispatchQueueSize() {
return 0;
}
@Override
public Connector getConnector() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getConnectionId() {
return null;
}
@Override
public void dispatchSync(Command message) {
}
@Override
public void dispatchAsync(Command command) {
}
@Override
public int getActiveTransactionCount() {
return 0;
}
@Override
public Long getOldestActiveTransactionDuration() {
return null;
}
});
final DestinationStatistics destinationStatistics = new DestinationStatistics();
final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
final MockMemoryUsage usage = new MockMemoryUsage();
queue.setOptimizedDispatch(true);
queue.initialize();
queue.start();
queue.memoryUsage = usage;
ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
ProducerInfo producerInfo = new ProducerInfo();
ProducerState producerState = new ProducerState(producerInfo);
producerExchange.setProducerState(producerState);
producerExchange.setConnectionContext(contextNotInTx);
// populate the queue store, exceed memory limit so that cache is disabled
for (int i = 0; i < count; i++) {
Message message = getMessage(i);
queue.send(producerExchange, message);
}
usage.setFull(false);
try {
queue.wakeup();
} catch (Exception e) {
LOG.error("Queue threw an unexpected exception: " + e.toString());
fail("Should not throw an exception.");
}
}
use of org.apache.activemq.broker.Connection in project beam by apache.
the class MqttIOTest method testRead.
@Test(timeout = 30 * 1000)
@Ignore("https://issues.apache.org/jira/browse/BEAM-5150 Flake Non-deterministic output.")
public void testRead() throws Exception {
PCollection<byte[]> output = pipeline.apply(MqttIO.read().withConnectionConfiguration(MqttIO.ConnectionConfiguration.create("tcp://localhost:" + port, "READ_TOPIC").withClientId("READ_PIPELINE")).withMaxReadTime(Duration.standardSeconds(3)));
PAssert.that(output).containsInAnyOrder("This is test 0".getBytes(StandardCharsets.UTF_8), "This is test 1".getBytes(StandardCharsets.UTF_8), "This is test 2".getBytes(StandardCharsets.UTF_8), "This is test 3".getBytes(StandardCharsets.UTF_8), "This is test 4".getBytes(StandardCharsets.UTF_8), "This is test 5".getBytes(StandardCharsets.UTF_8), "This is test 6".getBytes(StandardCharsets.UTF_8), "This is test 7".getBytes(StandardCharsets.UTF_8), "This is test 8".getBytes(StandardCharsets.UTF_8), "This is test 9".getBytes(StandardCharsets.UTF_8));
// produce messages on the brokerService in another thread
// This thread prevents to block the pipeline waiting for new messages
MQTT client = new MQTT();
client.setHost("tcp://localhost:" + port);
final BlockingConnection publishConnection = client.blockingConnection();
publishConnection.connect();
Thread publisherThread = new Thread(() -> {
try {
LOG.info("Waiting pipeline connected to the MQTT broker before sending " + "messages ...");
boolean pipelineConnected = false;
while (!pipelineConnected) {
Thread.sleep(1000);
for (Connection connection : brokerService.getBroker().getClients()) {
if (connection.getConnectionId().startsWith("READ_PIPELINE")) {
pipelineConnected = true;
}
}
}
for (int i = 0; i < 10; i++) {
publishConnection.publish("READ_TOPIC", ("This is test " + i).getBytes(StandardCharsets.UTF_8), QoS.EXACTLY_ONCE, false);
}
} catch (Exception e) {
// nothing to do
}
});
publisherThread.start();
pipeline.run();
publisherThread.join();
publishConnection.disconnect();
}
use of org.apache.activemq.broker.Connection in project beam by apache.
the class MqttIOTest method testReadNoClientId.
@Test(timeout = 60 * 1000)
@Ignore("https://issues.apache.org/jira/browse/BEAM-3604 Test timeout failure.")
public void testReadNoClientId() throws Exception {
final String topicName = "READ_TOPIC_NO_CLIENT_ID";
Read mqttReader = MqttIO.read().withConnectionConfiguration(MqttIO.ConnectionConfiguration.create("tcp://localhost:" + port, topicName)).withMaxNumRecords(10);
PCollection<byte[]> output = pipeline.apply(mqttReader);
PAssert.that(output).containsInAnyOrder("This is test 0".getBytes(StandardCharsets.UTF_8), "This is test 1".getBytes(StandardCharsets.UTF_8), "This is test 2".getBytes(StandardCharsets.UTF_8), "This is test 3".getBytes(StandardCharsets.UTF_8), "This is test 4".getBytes(StandardCharsets.UTF_8), "This is test 5".getBytes(StandardCharsets.UTF_8), "This is test 6".getBytes(StandardCharsets.UTF_8), "This is test 7".getBytes(StandardCharsets.UTF_8), "This is test 8".getBytes(StandardCharsets.UTF_8), "This is test 9".getBytes(StandardCharsets.UTF_8));
// produce messages on the brokerService in another thread
// This thread prevents to block the pipeline waiting for new messages
MQTT client = new MQTT();
client.setHost("tcp://localhost:" + port);
final BlockingConnection publishConnection = client.blockingConnection();
publishConnection.connect();
Thread publisherThread = new Thread(() -> {
try {
LOG.info("Waiting pipeline connected to the MQTT broker before sending " + "messages ...");
boolean pipelineConnected = false;
while (!pipelineConnected) {
Thread.sleep(1000);
for (Connection connection : brokerService.getBroker().getClients()) {
if (!connection.getConnectionId().isEmpty()) {
pipelineConnected = true;
}
}
}
for (int i = 0; i < 10; i++) {
publishConnection.publish(topicName, ("This is test " + i).getBytes(StandardCharsets.UTF_8), QoS.EXACTLY_ONCE, false);
}
} catch (Exception e) {
// nothing to do
}
});
publisherThread.start();
pipeline.run();
publishConnection.disconnect();
publisherThread.join();
}
Aggregations