Search in sources :

Example 6 with SessionId

use of org.apache.activemq.command.SessionId in project activemq-artemis by apache.

the class SessionIdTest method createObject.

@Override
public Object createObject() throws Exception {
    SessionId info = new SessionId();
    populateObject(info);
    return info;
}
Also used : SessionId(org.apache.activemq.command.SessionId)

Example 7 with SessionId

use of org.apache.activemq.command.SessionId in project activemq-artemis by apache.

the class SessionIdTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    SessionId info = (SessionId) object;
    info.setConnectionId("ConnectionId:1");
    info.setValue(1);
}
Also used : SessionId(org.apache.activemq.command.SessionId)

Example 8 with SessionId

use of org.apache.activemq.command.SessionId in project activemq-artemis by apache.

the class NetworkRouteTest method before.

@Before
public void before() throws Exception {
    control = EasyMock.createControl();
    localBroker = control.createMock(Transport.class);
    remoteBroker = control.createMock(Transport.class);
    NetworkBridgeConfiguration configuration = new NetworkBridgeConfiguration();
    brokerService = new BrokerService();
    BrokerInfo remoteBrokerInfo = new BrokerInfo();
    configuration.setDuplex(true);
    configuration.setNetworkTTL(5);
    brokerService.setBrokerId("broker-1");
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.start();
    brokerService.waitUntilStarted();
    remoteBrokerInfo.setBrokerId(new BrokerId("remote-broker-id"));
    remoteBrokerInfo.setBrokerName("remote-broker-name");
    localBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder localListenerRef = ArgHolder.holdArgsForLastVoidCall();
    remoteBroker.setTransportListener(EasyMock.isA(TransportListener.class));
    ArgHolder remoteListenerRef = ArgHolder.holdArgsForLastVoidCall();
    localBroker.start();
    remoteBroker.start();
    remoteBroker.oneway(EasyMock.isA(Object.class));
    EasyMock.expectLastCall().times(4);
    remoteBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter remoteInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    localBroker.oneway(remoteBrokerInfo);
    EasyMock.expect(localBroker.request(EasyMock.isA(Object.class))).andReturn(null);
    localBroker.oneway(EasyMock.isA(Object.class));
    ExpectationWaiter localInitWaiter = ExpectationWaiter.waiterForLastVoidCall();
    control.replay();
    DurableConduitBridge bridge = new DurableConduitBridge(configuration, localBroker, remoteBroker);
    bridge.setBrokerService(brokerService);
    bridge.start();
    localListener = (TransportListener) localListenerRef.getArguments()[0];
    Assert.assertNotNull(localListener);
    remoteListener = (TransportListener) remoteListenerRef.getArguments()[0];
    Assert.assertNotNull(remoteListener);
    remoteListener.onCommand(remoteBrokerInfo);
    remoteInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    localInitWaiter.assertHappens(5, TimeUnit.SECONDS);
    control.verify();
    control.reset();
    ActiveMQMessage msg = new ActiveMQMessage();
    msg.setDestination(new ActiveMQTopic("test"));
    msgDispatch = new MessageDispatch();
    msgDispatch.setMessage(msg);
    ConsumerInfo path1 = new ConsumerInfo();
    path1.setDestination(msg.getDestination());
    path1.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-1"), 1), 3));
    path1.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(1)-broker-id") });
    path1Msg = new ActiveMQMessage();
    path1Msg.setDestination(AdvisorySupport.getConsumerAdvisoryTopic(path1.getDestination()));
    path1Msg.setDataStructure(path1);
    ConsumerInfo path2 = new ConsumerInfo();
    path2.setDestination(path1.getDestination());
    path2.setConsumerId(new ConsumerId(new SessionId(new ConnectionId("conn-id-2"), 2), 4));
    path2.setBrokerPath(new BrokerId[] { new BrokerId("remote-broker-id"), new BrokerId("server(2)-broker-id"), new BrokerId("server(1)-broker-id") });
    path2Msg = new ActiveMQMessage();
    path2Msg.setDestination(path1Msg.getDestination());
    path2Msg.setDataStructure(path2);
    RemoveInfo removePath1 = new RemoveInfo(path1.getConsumerId());
    RemoveInfo removePath2 = new RemoveInfo(path2.getConsumerId());
    removePath1Msg = new ActiveMQMessage();
    removePath1Msg.setDestination(path1Msg.getDestination());
    removePath1Msg.setDataStructure(removePath1);
    removePath2Msg = new ActiveMQMessage();
    removePath2Msg.setDestination(path1Msg.getDestination());
    removePath2Msg.setDataStructure(removePath2);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) BrokerId(org.apache.activemq.command.BrokerId) BrokerInfo(org.apache.activemq.command.BrokerInfo) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) TransportListener(org.apache.activemq.transport.TransportListener) MessageDispatch(org.apache.activemq.command.MessageDispatch) ConnectionId(org.apache.activemq.command.ConnectionId) RemoveInfo(org.apache.activemq.command.RemoveInfo) ConsumerId(org.apache.activemq.command.ConsumerId) Transport(org.apache.activemq.transport.Transport) BrokerService(org.apache.activemq.broker.BrokerService) SessionId(org.apache.activemq.command.SessionId) Before(org.junit.Before)

Example 9 with SessionId

use of org.apache.activemq.command.SessionId in project activemq-artemis by apache.

the class NumberRangesWhileMarshallingTest method testLongNumberRanges.

public void testLongNumberRanges() throws Exception {
    long[] numberValues = { // bytes
    0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xf0, 0xff, // shorts
    0x7eff, 0x7fffL, 0x8001L, 0x8000L, 0xe000L, 0xe0001L, 0xff00L, 0xffffL, // ints
    0x10000L, 0x700000L, 0x12345678L, 0x72345678L, 0x7fffffffL, 0x80000000L, 0x80000001L, 0xE0000001L, 0xFFFFFFFFL, // 3 byte longs
    0x123456781L, 0x1234567812L, 0x12345678123L, 0x123456781234L, 0x1234567812345L, 0x12345678123456L, 0x7e345678123456L, 0x7fffffffffffffL, 0x80000000000000L, 0x80000000000001L, 0xe0000000000001L, 0xffffffffffffffL, // 4 byte longs
    0x1234567812345678L, 0x7fffffffffffffffL, 0x8000000000000000L, 0x8000000000000001L, 0xe000000000000001L, 0xffffffffffffffffL, 1 };
    for (int i = 0; i < numberValues.length; i++) {
        long value = numberValues[i];
        SessionId object = new SessionId();
        object.setConnectionId(connectionId);
        object.setValue(value);
        writeObject(object);
    }
    ds.writeInt(endOfStreamMarker);
    // now lets read from the stream
    ds.close();
    ByteArrayInputStream in = new ByteArrayInputStream(buffer.toByteArray());
    DataInputStream dis = new DataInputStream(in);
    for (int i = 0; i < numberValues.length; i++) {
        long value = numberValues[i];
        String expected = Long.toHexString(value);
        LOG.info("Unmarshaling value: " + i + " = " + expected);
        SessionId command = (SessionId) openWireformat.unmarshal(dis);
        assertEquals("connection ID in object: " + i, connectionId, command.getConnectionId());
        String actual = Long.toHexString(command.getValue());
        assertEquals("value of object: " + i + " was: " + actual, expected, actual);
    }
    int marker = dis.readInt();
    assertEquals("Marker int", Integer.toHexString(endOfStreamMarker), Integer.toHexString(marker));
    // lets try read and we should get an exception
    try {
        byte value = dis.readByte();
        fail("Should have reached the end of the stream: " + value);
    } catch (IOException e) {
    // worked!
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) SessionId(org.apache.activemq.command.SessionId)

Example 10 with SessionId

use of org.apache.activemq.command.SessionId in project activemq-artemis by apache.

the class ConcurrentConnectSimulationTest method testConcurrentConnection.

/*
    * simulate failover and retry of connection before broker has killed connection
    * which appears as a concurrent connect request to the broker
    * see: https://issues.apache.org/activemq/browse/AMQ-2241
    */
public void testConcurrentConnection() throws Exception {
    StubConnection connection1 = createConnection();
    StubConnection connection2 = createConnection();
    // reuse same connection info
    ConnectionInfo connectionInfo = createConnectionInfo();
    connection1.request(connectionInfo);
    connection2.request(connectionInfo);
    // second one should win out, verify using consumer on default session (watchAdvisories)
    ConsumerId consumerId = new ConsumerId(new SessionId(connectionInfo.getConnectionId(), -1), 1);
    ConsumerInfo consumerInfo = new ConsumerInfo(consumerId);
    consumerInfo.setDestination(AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC);
    connection2.request(consumerInfo);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ConsumerId(org.apache.activemq.command.ConsumerId) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) SessionId(org.apache.activemq.command.SessionId)

Aggregations

SessionId (org.apache.activemq.command.SessionId)23 ConnectionId (org.apache.activemq.command.ConnectionId)3 ConsumerId (org.apache.activemq.command.ConsumerId)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 IllegalStateException (javax.jms.IllegalStateException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 AMQConsumer (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConsumer)1 AMQSession (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQSession)1 BrokerService (org.apache.activemq.broker.BrokerService)1 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)1 BrokerId (org.apache.activemq.command.BrokerId)1 BrokerInfo (org.apache.activemq.command.BrokerInfo)1 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)1 DestinationInfo (org.apache.activemq.command.DestinationInfo)1 MessageDispatch (org.apache.activemq.command.MessageDispatch)1 RemoveInfo (org.apache.activemq.command.RemoveInfo)1