unmarshalledMessage.put(MessageSchema.MESSAGE_POSITION, position); KapuaPayload payload = message.getPayload(); if (payload == null) { return unmarshalledMessage;
private boolean checkThatDatastoreMessagesMatch(DatastoreMessage firstMsg, DatastoreMessage secondMsg) throws KapuaException { assertEquals(firstMsg.getDatastoreId().toString(), secondMsg.getDatastoreId().toString()); assertTrue(areSemanticPartsEqual(firstMsg.getChannel().getSemanticParts(), secondMsg.getChannel().getSemanticParts())); if ((firstMsg.getPayload() != null) || (secondMsg.getPayload() != null)) { assertArrayEquals(firstMsg.getPayload().getBody(), secondMsg.getPayload().getBody()); assertTrue(areMetricsEqual(firstMsg.getPayload().getMetrics(), secondMsg.getPayload().getMetrics())); } assertTrue(arePositionsEqual(firstMsg.getPosition(), secondMsg.getPosition())); assertEquals(firstMsg.getTimestamp(), secondMsg.getTimestamp()); assertEquals(firstMsg.getCapturedOn(), secondMsg.getCapturedOn()); assertEquals(firstMsg.getSentOn(), secondMsg.getSentOn()); assertEquals(firstMsg.getReceivedOn(), secondMsg.getReceivedOn()); return true; }
@Then("^The datastore messages \"(.*)\" and \"(.*)\" match$") public void checkSavedMessages(String firstMsg, String secondMsg) throws KapuaException { DatastoreMessage origMsg = (DatastoreMessage) stepData.get(firstMsg); DatastoreMessage foundMsg = (DatastoreMessage) stepData.get(secondMsg); checkThatDatastoreMessagesMatch(origMsg, foundMsg); isChannelForFirstMessageInStoreOK(foundMsg.getDatastoreId(), foundMsg.getTimestamp()); isClientForFirstMessageInStoreOK(foundMsg.getDatastoreId(), foundMsg.getTimestamp()); if ((origMsg.getPayload() != null) || (foundMsg.getPayload() != null)) { isMetricForFirstMessageInStoreOK(foundMsg.getDatastoreId(), foundMsg.getTimestamp()); } }
private boolean checkThatTheInsertedMessageMatchesTheOriginal(KapuaDataMessage origMsg, DatastoreMessage foundMsg) throws KapuaException { assertTrue(areSemanticPartsEqual(origMsg.getChannel().getSemanticParts(), foundMsg.getChannel().getSemanticParts())); if (origMsg.getPayload() != null) { assertArrayEquals(origMsg.getPayload().getBody(), foundMsg.getPayload().getBody()); assertTrue(areMetricsEqual(origMsg.getPayload().getMetrics(), foundMsg.getPayload().getMetrics())); } assertTrue(arePositionsEqual(origMsg.getPosition(), foundMsg.getPosition())); assertTrue(foundMsg.getTimestamp().compareTo(origMsg.getReceivedOn()) >= 0); assertTrue(foundMsg.getTimestamp().compareTo(new Date(origMsg.getReceivedOn().getTime() + 10000)) <= 0); assertEquals(origMsg.getCapturedOn(), foundMsg.getCapturedOn()); assertEquals(origMsg.getSentOn(), foundMsg.getSentOn()); assertEquals(origMsg.getReceivedOn(), foundMsg.getReceivedOn()); return true; }
@Then("I expect the latest captured message on channel \"(.*)\" to have the metrics") public void testMessageData(final String topic, final List<MetricEntry> expectedMetrics) throws Exception { final MessageStoreService service = KapuaLocator.getInstance().getService(MessageStoreService.class); session.withLogin(() -> { With.withUserAccount(currentDevice.getAccountName(), account -> { // start a new query final MessageQueryImpl query = new MessageQueryImpl(account.getId()); // query for client and channel final AndPredicateImpl and = new AndPredicateImpl(); and.getPredicates().add(new TermPredicateImpl(MessageField.CLIENT_ID, currentDevice.getClientId())); and.getPredicates().add(new TermPredicateImpl(MessageField.CHANNEL, topic)); query.setPredicate(and); // sort by captured time query.setSortFields(Arrays.asList(SortField.descending(MessageField.CAPTURED_ON.field()))); // perform the query final MessageListResult result = service.query(query); Assert.assertEquals(1, result.getSize()); // get the first item final DatastoreMessage message = result.getFirstItem(); Assert.assertEquals(currentDevice.getClientId(), message.getClientId()); // get payload structure final KapuaPayload payload = message.getPayload(); // assert metrics data final Map<String, Object> properties = payload.getMetrics(); Assert.assertEquals(toData(expectedMetrics), properties); }); }); }
channelInfoStoreFacade.upstore(channelInfo); KapuaPayload payload = message.getPayload(); if (payload == null) { return;
public JsonDatastoreMessage(DatastoreMessage datastoreMessage) { super(); setId(datastoreMessage.getId()); setDatastoreId(datastoreMessage.getDatastoreId()); setTimestamp(datastoreMessage.getTimestamp()); setScopeId(datastoreMessage.getScopeId()); setDeviceId(datastoreMessage.getDeviceId()); setClientId(datastoreMessage.getClientId()); setReceivedOn(datastoreMessage.getReceivedOn()); setSentOn(datastoreMessage.getSentOn()); setCapturedOn(datastoreMessage.getCapturedOn()); setPosition(datastoreMessage.getPosition()); setChannel((KapuaDataChannel) datastoreMessage.getChannel()); setPayload(datastoreMessage.getPayload()); }