use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ResourceAdapterTest method testCreateConnectionFactoryOverrides.
@Test
public void testCreateConnectionFactoryOverrides() throws Exception {
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(InVMConnectorFactory.class.getName());
ConnectionFactoryProperties connectionFactoryProperties = new ConnectionFactoryProperties();
connectionFactoryProperties.setAutoGroup(!ActiveMQClient.DEFAULT_AUTO_GROUP);
connectionFactoryProperties.setBlockOnAcknowledge(!ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE);
connectionFactoryProperties.setBlockOnNonDurableSend(!ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND);
connectionFactoryProperties.setBlockOnDurableSend(!ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND);
connectionFactoryProperties.setCallTimeout(1L);
connectionFactoryProperties.setClientFailureCheckPeriod(2L);
connectionFactoryProperties.setClientID("myid");
connectionFactoryProperties.setConnectionLoadBalancingPolicyClassName("mlbcn");
connectionFactoryProperties.setConnectionTTL(3L);
connectionFactoryProperties.setConsumerMaxRate(4);
connectionFactoryProperties.setConsumerWindowSize(5);
connectionFactoryProperties.setDiscoveryInitialWaitTimeout(6L);
connectionFactoryProperties.setDiscoveryRefreshTimeout(7L);
connectionFactoryProperties.setDupsOKBatchSize(8);
connectionFactoryProperties.setMinLargeMessageSize(10);
connectionFactoryProperties.setPreAcknowledge(!ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE);
connectionFactoryProperties.setProducerMaxRate(11);
connectionFactoryProperties.setConfirmationWindowSize(12);
connectionFactoryProperties.setReconnectAttempts(13);
connectionFactoryProperties.setRetryInterval(14L);
connectionFactoryProperties.setRetryIntervalMultiplier(15d);
connectionFactoryProperties.setScheduledThreadPoolMaxSize(16);
connectionFactoryProperties.setThreadPoolMaxSize(17);
connectionFactoryProperties.setTransactionBatchSize(18);
connectionFactoryProperties.setUseGlobalPools(!ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS);
ActiveMQConnectionFactory factory = ra.getConnectionFactory(connectionFactoryProperties);
Assert.assertEquals(factory.getCallTimeout(), 1);
Assert.assertEquals(factory.getClientFailureCheckPeriod(), 2);
Assert.assertEquals(factory.getClientID(), "myid");
Assert.assertEquals(factory.getConnectionLoadBalancingPolicyClassName(), "mlbcn");
Assert.assertEquals(factory.getConnectionTTL(), 3);
Assert.assertEquals(factory.getConsumerMaxRate(), 4);
Assert.assertEquals(factory.getConsumerWindowSize(), 5);
Assert.assertEquals(factory.getDupsOKBatchSize(), 8);
Assert.assertEquals(factory.getMinLargeMessageSize(), 10);
Assert.assertEquals(factory.getProducerMaxRate(), 11);
Assert.assertEquals(factory.getConfirmationWindowSize(), 12);
Assert.assertEquals(factory.getReconnectAttempts(), 13);
Assert.assertEquals(factory.getRetryInterval(), 14);
Assert.assertEquals(factory.getRetryIntervalMultiplier(), 15d, 0.000001);
Assert.assertEquals(factory.getScheduledThreadPoolMaxSize(), 16);
Assert.assertEquals(factory.getThreadPoolMaxSize(), 17);
Assert.assertEquals(factory.getTransactionBatchSize(), 18);
Assert.assertEquals(factory.isAutoGroup(), !ActiveMQClient.DEFAULT_AUTO_GROUP);
Assert.assertEquals(factory.isBlockOnAcknowledge(), !ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE);
Assert.assertEquals(factory.isBlockOnNonDurableSend(), !ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND);
Assert.assertEquals(factory.isBlockOnDurableSend(), !ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND);
Assert.assertEquals(factory.isPreAcknowledge(), !ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE);
Assert.assertEquals(factory.isUseGlobalPools(), !ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS);
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter 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.ActiveMQResourceAdapter 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.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ResourceAdapterTest method testActivationDeserializationParameters.
@Test
public void testActivationDeserializationParameters() throws Exception {
ActiveMQServer server = createServer(false);
try {
server.start();
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
ra.setDeserializationWhiteList("a.b.c.d.e");
ra.setDeserializationBlackList("f.g.h.i.j");
ra.start(new BootstrapContext());
ActiveMQConnectionFactory factory = ra.getDefaultActiveMQConnectionFactory();
assertEquals("a.b.c.d.e", factory.getDeserializationWhiteList());
assertEquals("f.g.h.i.j", factory.getDeserializationBlackList());
ConnectionFactoryProperties overrides = new ConnectionFactoryProperties();
overrides.setDeserializationWhiteList("k.l.m.n");
overrides.setDeserializationBlackList("o.p.q.r");
factory = ra.newConnectionFactory(overrides);
assertEquals("k.l.m.n", factory.getDeserializationWhiteList());
assertEquals("o.p.q.r", factory.getDeserializationBlackList());
ra.stop();
} finally {
server.stop();
}
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ResourceAdapterTest method testCreateConnectionFactoryMultipleConnectorsOverrideAndParams.
@Test
public void testCreateConnectionFactoryMultipleConnectorsOverrideAndParams() {
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY);
ra.setConnectionParameters("host=host1;port=61616, serverid=0, host=host2;port=61617");
ConnectionFactoryProperties overrideProperties = new ConnectionFactoryProperties();
ArrayList<String> value = new ArrayList<>();
value.add(INVM_CONNECTOR_FACTORY);
value.add(NETTY_CONNECTOR_FACTORY);
value.add(INVM_CONNECTOR_FACTORY);
overrideProperties.setParsedConnectorClassNames(value);
ArrayList<Map<String, Object>> connectionParameters = new ArrayList<>();
Map<String, Object> map1 = new HashMap<>();
map1.put("serverid", "0");
connectionParameters.add(map1);
Map<String, Object> map2 = new HashMap<>();
map2.put("host", "myhost");
map2.put("port", "61616");
connectionParameters.add(map2);
Map<String, Object> map3 = new HashMap<>();
map3.put("serverid", "1");
connectionParameters.add(map3);
overrideProperties.setParsedConnectionParameters(connectionParameters);
ActiveMQConnectionFactory factory = ra.getConnectionFactory(overrideProperties);
TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations();
assertNotNull(configurations);
assertEquals(3, configurations.length);
assertEquals(INVM_CONNECTOR_FACTORY, configurations[0].getFactoryClassName());
assertEquals(1, configurations[0].getParams().size());
assertEquals("0", configurations[0].getParams().get("serverid"));
assertEquals(NETTY_CONNECTOR_FACTORY, configurations[1].getFactoryClassName());
assertEquals(2, configurations[1].getParams().size());
assertEquals("myhost", configurations[1].getParams().get("host"));
assertEquals("61616", configurations[1].getParams().get("port"));
assertEquals(INVM_CONNECTOR_FACTORY, configurations[2].getFactoryClassName());
assertEquals(1, configurations[2].getParams().size());
assertEquals("1", configurations[2].getParams().get("serverid"));
}
Aggregations