Search in sources :

Example 1 with JsonLongImpl

use of org.apache.johnzon.core.JsonLongImpl in project activemq-artemis by apache.

the class ManagementWithPagingServerTest method testListMessagesAsJSON.

@Test
public void testListMessagesAsJSON() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session1.createQueue(address, queue, null, true);
    QueueControl queueControl = createManagementControl(address, queue);
    int num = 1000;
    SenderThread sender = new SenderThread(address, num, 0);
    ReceiverThread receiver = new ReceiverThread(queue, num, 0);
    // kick off sender
    sender.start();
    // wait for all messages sent
    sender.join();
    assertNull(sender.getError());
    long count = queueControl.countMessages(null);
    assertEquals(num, count);
    String result = queueControl.listMessagesAsJSON(null);
    JsonArray array = JsonUtil.readJsonArray(result);
    List<Long> longs = new ArrayList<>();
    for (JsonValue jsonValue : array) {
        JsonValue val = ((JsonObject) jsonValue).get("messageID");
        Long l = ((JsonLongImpl) val).longValue();
        if (longs.contains(l)) {
            System.out.println("ManagementWithPagingServerTest.testListMessagesAsJSON");
        }
        longs.add(l);
        System.out.println("jsonValue = " + jsonValue);
    }
    assertEquals(num, array.size());
    // kick off receiver
    receiver.start();
    receiver.join();
    assertNull(receiver.getError());
    result = queueControl.listMessagesAsJSON(null);
    array = JsonUtil.readJsonArray(result);
    assertEquals(0, array.size());
}
Also used : JsonLongImpl(org.apache.johnzon.core.JsonLongImpl) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) JsonArray(javax.json.JsonArray) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 JsonValue (javax.json.JsonValue)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)1 JsonLongImpl (org.apache.johnzon.core.JsonLongImpl)1 Test (org.junit.Test)1