@Override public void run() { if (stopFlag.get()) { return; } try { String result = queueControl.listMessageCounter(); MessageCounterInfo info = MessageCounterInfo.fromJSON(result); if (info.getCountDelta() != 0) { System.out.println("non zero value got ---> " + info.getCountDelta()); } results.add(info); resultLatch.countDown(); if (info.getCountDelta() < 0) { //stop and make the test finish quick stopFlag.set(true); while (resultLatch.getCount() > 0) { resultLatch.countDown(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (!stopFlag.get()) { timer1.schedule(new MessageCounterCollector(this.queueControl, resultLatch), 200); } } } }
private String dumpResults(List<MessageCounterInfo> results) { StringBuilder builder = new StringBuilder("\n"); for (int i = 0; i < results.size(); i++) { builder.append("result[" + i + "]: " + results.get(i).getCountDelta() + " " + results.get(i).getCount() + "\n"); } return builder.toString(); }
MessageCounterInfo info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(0, info.getDepth()); Assert.assertEquals(0, info.getCount()); info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(1, info.getDepth()); Assert.assertEquals(1, info.getDepthDelta()); Assert.assertEquals(1, info.getCount()); Assert.assertEquals(1, info.getCountDelta()); info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(0, info.getDepth()); Assert.assertEquals(-1, info.getDepthDelta()); Assert.assertEquals(1, info.getCount()); Assert.assertEquals(0, info.getCountDelta()); info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(0, info.getDepth()); Assert.assertEquals(0, info.getDepthDelta()); Assert.assertEquals(0, info.getCount()); Assert.assertEquals(0, info.getCountDelta());
/** * Returns a MessageCounterInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounter()}. */ public static MessageCounterInfo fromJSON(final String jsonString) throws Exception { JsonObject data = JsonUtil.readJsonObject(jsonString); String name = data.getString("destinationName"); String subscription = data.getString("destinationSubscription", null); boolean durable = data.getBoolean("destinationDurable"); long count = data.getJsonNumber("count").longValue(); long countDelta = data.getJsonNumber("countDelta").longValue(); int depth = data.getInt("messageCount"); int depthDelta = data.getInt("messageCountDelta"); String lastAddTimestamp = data.getString("lastAddTimestamp"); String updateTimestamp = data.getString("updateTimestamp"); return new MessageCounterInfo(name, subscription, durable, count, countDelta, depth, depthDelta, lastAddTimestamp, updateTimestamp); }
assertTrue("countDelta should be positive " + info.getCountDelta() + dumpResults(results), info.getCountDelta() >= 0);
MessageCounterInfo info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(0, info.getDepth()); Assert.assertEquals(0, info.getCount()); info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(1, info.getDepth()); Assert.assertEquals(1, info.getDepthDelta()); Assert.assertEquals(1, info.getCount()); Assert.assertEquals(1, info.getCountDelta()); info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(2, info.getDepth()); Assert.assertEquals(1, info.getDepthDelta()); Assert.assertEquals(2, info.getCount()); Assert.assertEquals(1, info.getCountDelta()); info = MessageCounterInfo.fromJSON(jsonString); Assert.assertEquals(0, info.getDepth()); Assert.assertEquals(-2, info.getDepthDelta()); Assert.assertEquals(2, info.getCount()); Assert.assertEquals(0, info.getCountDelta());
/** * Returns a MessageCounterInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounter()}. */ public static MessageCounterInfo fromJSON(final String jsonString) throws Exception { JsonObject data = JsonUtil.readJsonObject(jsonString); String name = data.getString("destinationName"); String subscription = data.getString("destinationSubscription", null); boolean durable = data.getBoolean("destinationDurable"); long count = data.getJsonNumber("count").longValue(); long countDelta = data.getJsonNumber("countDelta").longValue(); int depth = data.getInt("messageCount"); int depthDelta = data.getInt("messageCountDelta"); String lastAddTimestamp = data.getString("lastAddTimestamp"); String updateTimestamp = data.getString("updateTimestamp"); return new MessageCounterInfo(name, subscription, durable, count, countDelta, depth, depthDelta, lastAddTimestamp, updateTimestamp); }
/** * Returns a MessageCounterInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounter()}. */ public static MessageCounterInfo fromJSON(final String jsonString) throws Exception { JsonObject data = JsonUtil.readJsonObject(jsonString); String name = data.getString("destinationName"); String subscription = data.getString("destinationSubscription", null); boolean durable = data.getBoolean("destinationDurable"); long count = data.getJsonNumber("count").longValue(); long countDelta = data.getJsonNumber("countDelta").longValue(); int depth = data.getInt("messageCount"); int depthDelta = data.getInt("messageCountDelta"); String lastAddTimestamp = data.getString("lastAddTimestamp"); String updateTimestamp = data.getString("updateTimestamp"); return new MessageCounterInfo(name, subscription, durable, count, countDelta, depth, depthDelta, lastAddTimestamp, updateTimestamp); }