use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivation in project activemq-artemis by apache.
the class ActiveMQClusteredTest method testNonDurableInCluster.
/**
* https://bugzilla.redhat.com/show_bug.cgi?id=1029076
* Look at the logs for this test, if you see exceptions it's an issue.
*
* @throws Exception
*/
@Test
public void testNonDurableInCluster() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.start(ctx);
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Topic");
spec.setDestination("mdbTopic");
spec.setSetupAttempts(5);
qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
CountDownLatch latch = new CountDownLatch(1);
DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
qResourceAdapter.endpointActivation(endpointFactory, spec);
ClientSession session = addClientSession(locator.createSessionFactory().createSession());
ClientProducer clientProducer = session.createProducer("mdbTopic");
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString("test");
clientProducer.send(message);
ActiveMQActivation activation = lookupActivation(qResourceAdapter);
SimpleString tempQueue = activation.getTopicTemporaryQueue();
assertNotNull(server.locateQueue(tempQueue));
assertNotNull(secondaryServer.locateQueue(tempQueue));
latch.await(5, TimeUnit.SECONDS);
assertNotNull(endpoint.lastMessage);
assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "test");
qResourceAdapter.endpointDeactivation(endpointFactory, spec);
qResourceAdapter.stop();
assertNull(server.locateQueue(tempQueue));
assertNull(secondaryServer.locateQueue(tempQueue));
}
use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivation in project activemq-artemis by apache.
the class MDBMultipleHandlersServerDisconnectTest method testReconnectMDBNoMessageLoss.
@Test
public void testReconnectMDBNoMessageLoss() throws Exception {
AddressSettings settings = new AddressSettings();
settings.setRedeliveryDelay(100);
settings.setMaxDeliveryAttempts(-1);
server.getAddressSettingsRepository().clear();
server.getAddressSettingsRepository().addMatch("#", settings);
ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
resourceAdapter = qResourceAdapter;
resourceAdapter.setConfirmationWindowSize(-1);
resourceAdapter.setCallTimeout(1000L);
resourceAdapter.setConsumerWindowSize(1024 * 1024);
resourceAdapter.setReconnectAttempts(-1);
resourceAdapter.setRetryInterval(100L);
// qResourceAdapter.setTransactionManagerLocatorClass(DummyTMLocator.class.getName());
// qResourceAdapter.setTransactionManagerLocatorMethod("getTM");
MyBootstrapContext ctx = new MyBootstrapContext();
qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
qResourceAdapter.start(ctx);
final int NUMBER_OF_SESSIONS = 10;
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setTransactionTimeout(1);
spec.setMaxSession(NUMBER_OF_SESSIONS);
spec.setSetupAttempts(-1);
spec.setSetupInterval(100L);
spec.setResourceAdapter(qResourceAdapter);
spec.setUseJNDI(false);
spec.setDestinationType("javax.jms.Queue");
spec.setDestination(MDBQUEUE);
// Some the routines would be screwed up if using the default one
Assert.assertFalse(spec.isHasBeenUpdated());
TestEndpointFactory endpointFactory = new TestEndpointFactory(true);
qResourceAdapter.endpointActivation(endpointFactory, spec);
Assert.assertEquals(1, resourceAdapter.getActivations().values().size());
ActiveMQActivation activation = resourceAdapter.getActivations().values().toArray(new ActiveMQActivation[1])[0];
final int NUMBER_OF_MESSAGES = 1000;
Thread producer = new Thread() {
@Override
public void run() {
try {
ServerLocator locator = createInVMLocator(0);
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, false);
ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
StringBuffer buffer = new StringBuffer();
for (int b = 0; b < 500; b++) {
buffer.append("ab");
}
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage message = session.createMessage(true);
message.getBodyBuffer().writeString(buffer.toString() + i);
message.putIntProperty("i", i);
clientProducer.send(message);
if (i % 100 == 0) {
session.commit();
}
}
session.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
};
producer.start();
final AtomicBoolean metaDataFailed = new AtomicBoolean(false);
Thread buggerThread = new Thread() {
@Override
public void run() {
while (running.get()) {
try {
Thread.sleep(RandomUtil.randomInterval(100, 200));
} catch (InterruptedException intex) {
intex.printStackTrace();
return;
}
List<ServerSession> serverSessions = lookupServerSessions("resource-adapter", NUMBER_OF_SESSIONS);
System.err.println("Contains " + serverSessions.size() + " RA sessions");
if (serverSessions.size() != NUMBER_OF_SESSIONS) {
System.err.println("the server was supposed to have " + NUMBER_OF_MESSAGES + " RA Sessions but it only contained accordingly to the meta-data");
metaDataFailed.set(true);
} else if (serverSessions.size() == NUMBER_OF_SESSIONS) {
// it became the same after some reconnect? which would be acceptable
metaDataFailed.set(false);
}
if (playServerClosingSession && serverSessions.size() > 0) {
int randomBother = RandomUtil.randomInterval(0, serverSessions.size() - 1);
System.out.println("bugging session " + randomBother);
ServerSession serverSession = serverSessions.get(randomBother);
if (playServerClosingConsumer && RandomUtil.randomBoolean()) {
// will play this randomly, only half of the times
for (ServerConsumer consumer : serverSession.getServerConsumers()) {
try {
// Simulating a rare race that could happen in production
// where the consumer is closed while things are still happening
consumer.close(true);
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
}
RemotingConnection connection = serverSession.getRemotingConnection();
connection.fail(new ActiveMQException("failed at random " + randomBother));
}
}
}
};
buggerThread.start();
ServerLocator locator = createInVMLocator(0);
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, false);
session.start();
ClientConsumer consumer = session.createConsumer("outQueue");
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage message = consumer.receive(60000);
if (message == null) {
break;
}
if (i == NUMBER_OF_MESSAGES * 0.50) {
// This is to make sure the MDBs will survive a reboot
// and no duplications or message loss will happen because of this
System.err.println("Rebooting the MDBs at least once!");
activation.startReconnectThread("I");
}
if (i == NUMBER_OF_MESSAGES * 0.90) {
System.out.println("Disabled failures at " + i);
playTXTimeouts = false;
playServerClosingSession = false;
playServerClosingConsumer = false;
}
System.out.println("Received " + i + " messages");
doReceiveMessage(message);
if (i % 200 == 0) {
System.out.println("received " + i);
session.commit();
}
}
session.commit();
while (true) {
ClientMessage message = consumer.receiveImmediate();
if (message == null) {
break;
}
System.out.println("Received extra message " + message);
doReceiveMessage(message);
}
session.commit();
Assert.assertNull(consumer.receiveImmediate());
StringWriter writer = new StringWriter();
PrintWriter out = new PrintWriter(writer);
boolean failed = false;
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
AtomicInteger atomicInteger = mapCounter.get(Integer.valueOf(i));
if (atomicInteger == null) {
out.println("didn't receive message with i=" + i);
failed = true;
} else if (atomicInteger.get() > 1) {
out.println("message with i=" + i + " received " + atomicInteger.get() + " times");
failed = true;
}
}
running.set(false);
buggerThread.join();
producer.join();
qResourceAdapter.stop();
session.close();
if (failed) {
for (int i = 0; i < 10; i++) {
System.out.println("----------------------------------------------------");
}
System.out.println(writer.toString());
}
Assert.assertFalse(writer.toString(), failed);
System.out.println("Received " + NUMBER_OF_MESSAGES + " messages");
Assert.assertFalse("There was meta-data failures, some sessions didn't reconnect properly", metaDataFailed.get());
}
use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivation in project activemq-artemis by apache.
the class ResourceAdapterTest method testForConnectionLeakDuringActivationWhenSessionCreationFails.
@Test
public void testForConnectionLeakDuringActivationWhenSessionCreationFails() throws Exception {
ActiveMQServer server = createServer(false);
ActiveMQResourceAdapter ra = null;
ActiveMQActivation activation = null;
try {
server.getConfiguration().setSecurityEnabled(true);
server.start();
ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ra.setUserName("badUser");
ra.setPassword("badPassword");
ra.start(new BootstrapContext());
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(ra);
spec.setUseJNDI(false);
spec.setUser("user");
spec.setPassword("password");
spec.setDestinationType("javax.jms.Topic");
spec.setDestination("test");
spec.setMinSession(1);
spec.setMaxSession(1);
spec.setSetupAttempts(1);
activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
try {
activation.start();
} catch (Exception e) {
// ignore
}
assertEquals(0, server.getRemotingService().getConnections().size());
} finally {
if (activation != null)
activation.stop();
if (ra != null)
ra.stop();
server.stop();
}
}
use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivation in project activemq-artemis by apache.
the class ResourceAdapterTest method testStartActivation.
@Test
public void testStartActivation() throws Exception {
ActiveMQServer server = createServer(false);
try {
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory factory = createSessionFactory(locator);
ClientSession session = factory.createSession(false, false, false);
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
session.close();
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
ra.start(new BootstrapContext());
Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
conn.close();
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(ra);
spec.setUseJNDI(false);
spec.setUser("user");
spec.setPassword("password");
spec.setDestinationType("javax.jms.Topic");
spec.setDestination("test");
spec.setMinSession(1);
spec.setMaxSession(1);
ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
activation.start();
activation.stop();
ra.stop();
locator.close();
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.ra.inflow.ActiveMQActivation in project activemq-artemis by apache.
the class ResourceAdapterTest method testStartStopActivationManyTimes.
@Test
public void testStartStopActivationManyTimes() throws Exception {
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession(false, false, false);
ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
session.close();
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
ra.start(new BootstrapContext());
Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
conn.close();
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
spec.setResourceAdapter(ra);
spec.setUseJNDI(false);
spec.setUser("user");
spec.setPassword("password");
spec.setDestinationType("javax.jms.Topic");
spec.setDestination("test");
spec.setMinSession(1);
spec.setMaxSession(15);
ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
ServerLocatorImpl serverLocator = (ServerLocatorImpl) ra.getDefaultActiveMQConnectionFactory().getServerLocator();
Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources();
for (int i = 0; i < 10; i++) {
System.out.println(i);
activation.start();
assertEquals(1, resources.size());
activation.stop();
}
ra.stop();
assertEquals(0, resources.size());
locator.close();
}
Aggregations