Search in sources :

Example 1 with ReleaseMessage

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;
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage)

Example 2 with 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());
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 3 with ReleaseMessage

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());
}
Also used : ReleaseMessageRepository(com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository) Mock(org.mockito.Mock) ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SettableFuture(com.google.common.util.concurrent.SettableFuture) TimeUnit(java.util.concurrent.TimeUnit) BizConfig(com.ctrip.framework.apollo.biz.config.BizConfig) Lists(com.google.common.collect.Lists) Environment(org.springframework.core.env.Environment) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 4 with ReleaseMessage

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;
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage)

Example 5 with ReleaseMessage

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));
}
Also used : ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) Test(org.junit.Test)

Aggregations

ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)28 Test (org.junit.Test)15 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)8 ResponseEntity (org.springframework.http.ResponseEntity)6 Release (com.ctrip.framework.apollo.biz.entity.Release)4 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)2 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)2 Transaction (com.ctrip.framework.apollo.tracer.spi.Transaction)2 List (java.util.List)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BizConfig (com.ctrip.framework.apollo.biz.config.BizConfig)1 ReleaseMessageRepository (com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository)1 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 DeferredResultWrapper (com.ctrip.framework.apollo.configservice.wrapper.DeferredResultWrapper)1 Cache (com.google.common.cache.Cache)1 CacheLoader (com.google.common.cache.CacheLoader)1 Lists (com.google.common.collect.Lists)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1