private Map<String, Object> marshalChannelInfo(ChannelInfo channelInfo) throws ParseException { Map<String, Object> unmarshalledChannelInfo = new HashMap<>(); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_NAME, channelInfo.getName()); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_TIMESTAMP, KapuaDateUtils.formatDate(channelInfo.getFirstMessageOn())); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_CLIENT_ID, channelInfo.getClientId()); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_SCOPE_ID, channelInfo.getScopeId().toStringId()); unmarshalledChannelInfo.put(ChannelInfoSchema.CHANNEL_MESSAGE_ID, channelInfo.getFirstMessageId().toString()); return unmarshalledChannelInfo; }
private void checkChannelInfoAgainstPreparedMessages(ChannelInfoListResult chnInfo, List<KapuaDataMessage> msgLst) { Set<String> msgTopics = new HashSet<>(); Set<String> msgClients = new HashSet<>(); Set<String> infoTopics = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No channel info data!", chnInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); msgTopics.add(tmpMsg.getChannel().toString()); } for (ChannelInfo tmpInfo : chnInfo.getItems()) { infoClients.add(tmpInfo.getClientId()); infoTopics.add(tmpInfo.getName()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); assertEquals("The number of topics does not match!", msgTopics.size(), infoTopics.size()); for (String tmpTopic : msgTopics) { assertTrue(String.format("The topic [%s] is not found in the info list!", tmpTopic), infoTopics.contains(tmpTopic)); } for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
/** * Get the channel identifier getting parameters from the channelInfo. Then it calls {@link ChannelInfoField#getOrDeriveId(StorableId id, KapuaId scopeId, String clientId, String channel)} * * @param id * @param channelInfo * @return */ public static String getOrDeriveId(StorableId id, ChannelInfo channelInfo) { return getOrDeriveId(id, channelInfo.getScopeId(), channelInfo.getClientId(), channelInfo.getName()); }
@Then("^Client \"(.+)\" first published on a channel in the list \"(.+)\" on \"(.+)\"$") public void checkFirstPublishDateOnChannel(String clientId, String lstKey, String date) throws Exception { ChannelInfoListResult chnList = (ChannelInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ChannelInfo tmpInfo : chnList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpCaptured, tmpInfo.getFirstMessageOn()); return; } } fail(String.format("No channel matches the client id [%s]", clientId)); }
@Then("^Client \"(.+)\" last published on a channel in the list \"(.+)\" on \"(.+)\"$") public void checkLastPublishDateOnChannel(String clientId, String lstKey, String date) throws Exception { ChannelInfoListResult chnList = (ChannelInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ChannelInfo tmpInfo : chnList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpCaptured, tmpInfo.getLastMessageOn()); return; } } fail(String.format("No channel matches the client id [%s]", clientId)); }
TermPredicate clientIdPredicate = storablePredicateFactory.newTermPredicate(MessageField.CLIENT_ID, channelInfo.getClientId()); TermPredicate channelPredicate = storablePredicateFactory.newTermPredicate(MessageField.CHANNEL, channelInfo.getName()); } else if (messageList.isEmpty()) { LOG.warn("Cannot find last timestamp for the specified client id '{}' - account '{}'", channelInfo.getScopeId(), channelInfo.getClientId()); } else { LOG.error("Cannot find last timestamp for the specified client id '{}' - account '{}'. More than one result returned by the query!", channelInfo.getScopeId(), channelInfo.getClientId());