Search in sources :

Example 1 with IdGenerator

use of org.apache.activemq.util.IdGenerator in project activemq-artemis by apache.

the class ActiveMQMessageAuditTest method testIsDuplicateString.

/**
 * test case for isDuplicate
 */
public void testIsDuplicateString() {
    int count = 10000;
    ActiveMQMessageAudit audit = new ActiveMQMessageAudit();
    IdGenerator idGen = new IdGenerator();
    // add to a list
    List<String> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        String id = idGen.generateId();
        list.add(id);
        assertFalse(audit.isDuplicate(id));
    }
    List<String> windowList = list.subList(list.size() - 1 - audit.getAuditDepth(), list.size() - 1);
    for (String id : windowList) {
        assertTrue("duplicate, id:" + id, audit.isDuplicate(id));
    }
}
Also used : ArrayList(java.util.ArrayList) IdGenerator(org.apache.activemq.util.IdGenerator)

Example 2 with IdGenerator

use of org.apache.activemq.util.IdGenerator in project activemq-artemis by apache.

the class JobSchedulerManagementTest method testRemoveNotScheduled.

@Test
public void testRemoveNotScheduled() throws Exception {
    Connection connection = createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Create the Browse Destination and the Reply To location
    Destination management = session.createTopic(ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION);
    MessageProducer producer = session.createProducer(management);
    try {
        // Send the remove request
        Message remove = session.createMessage();
        remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULER_ACTION, ScheduledMessage.AMQ_SCHEDULER_ACTION_REMOVEALL);
        remove.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_ID, new IdGenerator().generateId());
        producer.send(remove);
    } catch (Exception e) {
        fail("Caught unexpected exception during remove of unscheduled message.");
    }
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage) ScheduledMessage(org.apache.activemq.ScheduledMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) IdGenerator(org.apache.activemq.util.IdGenerator) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with IdGenerator

use of org.apache.activemq.util.IdGenerator in project activemq-artemis by apache.

the class ActiveMQMessageAuditTest method testIsInOrderString.

public void testIsInOrderString() {
    int count = 10000;
    ActiveMQMessageAudit audit = new ActiveMQMessageAudit();
    IdGenerator idGen = new IdGenerator();
    // add to a list
    List<String> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        String id = idGen.generateId();
        if (i == 0) {
            assertFalse(audit.isDuplicate(id));
            assertTrue(audit.isInOrder(id));
        }
        if (i > 1 && i % 2 != 0) {
            list.add(id);
        }
    }
    for (String id : list) {
        assertFalse(audit.isInOrder(id));
        assertFalse(audit.isDuplicate(id));
    }
}
Also used : ArrayList(java.util.ArrayList) IdGenerator(org.apache.activemq.util.IdGenerator)

Example 4 with IdGenerator

use of org.apache.activemq.util.IdGenerator in project activemq-artemis by apache.

the class DestinationMapTempDestinationTest method testtestTempDestinations.

public void testtestTempDestinations() throws Exception {
    ConnectionId id = new ConnectionId(new IdGenerator().generateId());
    DestinationMap map = new DestinationMap();
    Object value = new Object();
    int count = 1000;
    for (int i = 0; i < count; i++) {
        ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
        map.put(queue, value);
    }
    for (int i = 0; i < count; i++) {
        ActiveMQTempQueue queue = new ActiveMQTempQueue(id, i);
        map.remove(queue, value);
        Set<?> set = map.get(queue);
        assertTrue(set.isEmpty());
    }
}
Also used : ConnectionId(org.apache.activemq.command.ConnectionId) IdGenerator(org.apache.activemq.util.IdGenerator) ActiveMQTempQueue(org.apache.activemq.command.ActiveMQTempQueue)

Aggregations

IdGenerator (org.apache.activemq.util.IdGenerator)4 ArrayList (java.util.ArrayList)2 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 Message (javax.jms.Message)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 ScheduledMessage (org.apache.activemq.ScheduledMessage)1 ActiveMQTempQueue (org.apache.activemq.command.ActiveMQTempQueue)1 ConnectionId (org.apache.activemq.command.ConnectionId)1 Test (org.junit.Test)1