use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class GrayReleaseRulesHolderTest method assembleReleaseMessage.
private ReleaseMessage assembleReleaseMessage(String appId, String clusterName, String namespaceName) {
String message = STRING_JOINER.join(appId, clusterName, namespaceName);
ReleaseMessage releaseMessage = new ReleaseMessage(message);
return releaseMessage;
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class DatabaseMessageSenderTest method testSendMessage.
@Test
public void testSendMessage() throws Exception {
String someMessage = "some-message";
long someId = 1;
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
when(someReleaseMessage.getId()).thenReturn(someId);
when(releaseMessageRepository.save(any(ReleaseMessage.class))).thenReturn(someReleaseMessage);
ArgumentCaptor<ReleaseMessage> captor = ArgumentCaptor.forClass(ReleaseMessage.class);
messageSender.sendMessage(someMessage, Topics.APOLLO_RELEASE_TOPIC);
verify(releaseMessageRepository, times(1)).save(captor.capture());
assertEquals(someMessage, captor.getValue().getMessage());
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageScannerTest method testScanMessageAndNotifyMessageListener.
@Test
public void testScanMessageAndNotifyMessageListener() throws Exception {
SettableFuture<ReleaseMessage> someListenerFuture = SettableFuture.create();
ReleaseMessageListener someListener = (message, channel) -> someListenerFuture.set(message);
releaseMessageScanner.addMessageListener(someListener);
String someMessage = "someMessage";
long someId = 100;
ReleaseMessage someReleaseMessage = assembleReleaseMessage(someId, someMessage);
when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0L)).thenReturn(Lists.newArrayList(someReleaseMessage));
ReleaseMessage someListenerMessage = someListenerFuture.get(5000, TimeUnit.MILLISECONDS);
assertEquals(someMessage, someListenerMessage.getMessage());
assertEquals(someId, someListenerMessage.getId());
SettableFuture<ReleaseMessage> anotherListenerFuture = SettableFuture.create();
ReleaseMessageListener anotherListener = (message, channel) -> anotherListenerFuture.set(message);
releaseMessageScanner.addMessageListener(anotherListener);
String anotherMessage = "anotherMessage";
long anotherId = someId + 1;
ReleaseMessage anotherReleaseMessage = assembleReleaseMessage(anotherId, anotherMessage);
when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(someId)).thenReturn(Lists.newArrayList(anotherReleaseMessage));
ReleaseMessage anotherListenerMessage = anotherListenerFuture.get(5000, TimeUnit.MILLISECONDS);
assertEquals(anotherMessage, anotherListenerMessage.getMessage());
assertEquals(anotherId, anotherListenerMessage.getId());
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageService method findLatestReleaseMessagesGroupByMessages.
public List<ReleaseMessage> findLatestReleaseMessagesGroupByMessages(Collection<String> messages) {
if (CollectionUtils.isEmpty(messages)) {
return Collections.emptyList();
}
List<Object[]> result = releaseMessageRepository.findLatestReleaseMessagesGroupByMessages(messages);
List<ReleaseMessage> releaseMessages = Lists.newArrayList();
for (Object[] o : result) {
try {
ReleaseMessage releaseMessage = new ReleaseMessage((String) o[0]);
releaseMessage.setId((Long) o[1]);
releaseMessages.add(releaseMessage);
} catch (Exception ex) {
Tracer.logError("Parsing LatestReleaseMessagesGroupByMessages failed", ex);
}
}
return releaseMessages;
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageServiceWithCacheTest method testNewReleaseMessagesBeforeHandleMessage.
@Test
public void testNewReleaseMessagesBeforeHandleMessage() throws Exception {
String someMessageContent = "someMessage";
long someMessageId = 1;
ReleaseMessage someMessage = assembleReleaseMsg(someMessageId, someMessageContent);
when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0L)).thenReturn(Lists.newArrayList(someMessage));
releaseMessageServiceWithCache.afterPropertiesSet();
ReleaseMessage latestReleaseMsg = releaseMessageServiceWithCache.findLatestReleaseMessageForMessages(Sets.newHashSet(someMessageContent));
List<ReleaseMessage> latestReleaseMsgGroupByMsgContent = releaseMessageServiceWithCache.findLatestReleaseMessagesGroupByMessages(Sets.newHashSet(someMessageContent));
assertEquals(someMessageId, latestReleaseMsg.getId());
assertEquals(someMessageContent, latestReleaseMsg.getMessage());
assertEquals(latestReleaseMsg, latestReleaseMsgGroupByMsgContent.get(0));
long newMessageId = 2;
ReleaseMessage newMessage = assembleReleaseMsg(newMessageId, someMessageContent);
when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(someMessageId)).thenReturn(Lists.newArrayList(newMessage));
scanIntervalTimeUnit.sleep(scanInterval * 10);
ReleaseMessage newLatestReleaseMsg = releaseMessageServiceWithCache.findLatestReleaseMessageForMessages(Sets.newHashSet(someMessageContent));
List<ReleaseMessage> newLatestReleaseMsgGroupByMsgContent = releaseMessageServiceWithCache.findLatestReleaseMessagesGroupByMessages(Sets.newHashSet(someMessageContent));
assertEquals(newMessageId, newLatestReleaseMsg.getId());
assertEquals(someMessageContent, newLatestReleaseMsg.getMessage());
assertEquals(newLatestReleaseMsg, newLatestReleaseMsgGroupByMsgContent.get(0));
}
Aggregations