本文整理汇总了Java中org.springframework.web.context.request.async.DeferredResult.getResult方法的典型用法代码示例。如果您正苦于以下问题:Java DeferredResult.getResult方法的具体用法?Java DeferredResult.getResult怎么用?Java DeferredResult.getResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.request.async.DeferredResult
的用法示例。
在下文中一共展示了DeferredResult.getResult方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRegisterSuccess
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testRegisterSuccess() {
Device device = new Device();
device.setDeviceEUI("123");
device.setEntityType("type");
device.setEntityName("name");
device.setPort(1);
simulateAgentRegisterSuccess();
DeferredResult<ResponseEntity<?>> deferredResult = agentRestController.register(device);
verify(mockAgent, times(1)).register(eq(device), any(AgentSuccessCallback.class), any(AgentFailureCallback.class));
ResponseEntity<?> entity = (ResponseEntity<?>) deferredResult.getResult();
assertEquals(HttpStatus.CREATED, entity.getStatusCode());
assertEquals(String.format("/devices/%s", device.getDeviceEUI()), entity.getHeaders().get("Location").get(0));
}
示例2: testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated()
throws Exception {
long notificationId = someNotificationId + 1;
String releaseMessage = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, defaultNamespace);
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
String someWatchKey = "someKey";
Set<String> watchKeys = Sets.newHashSet(someWatchKey);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, defaultNamespace,
someDataCenter))
.thenReturn(
watchKeys);
when(someReleaseMessage.getId()).thenReturn(notificationId);
when(someReleaseMessage.getMessage()).thenReturn(releaseMessage);
when(releaseMessageService.findLatestReleaseMessageForMessages(watchKeys))
.thenReturn(someReleaseMessage);
DeferredResult<ResponseEntity<ApolloConfigNotification>>
deferredResult = controller
.pollNotification(someAppId, someCluster, defaultNamespace, someDataCenter,
someNotificationId, someClientIp);
ResponseEntity<ApolloConfigNotification> result =
(ResponseEntity<ApolloConfigNotification>) deferredResult.getResult();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(defaultNamespace, result.getBody().getNamespaceName());
assertEquals(notificationId, result.getBody().getNotificationId());
}
示例3: testPollNotificationWithDefaultNamespaceAndHandleMessage
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testPollNotificationWithDefaultNamespaceAndHandleMessage() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, defaultNamespace);
Set<String> watchKeys = Sets.newHashSet(someWatchKey, anotherWatchKey);
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster, defaultNamespace,
someDataCenter)).thenReturn(
watchKeys);
DeferredResult<ResponseEntity<ApolloConfigNotification>>
deferredResult = controller
.pollNotification(someAppId, someCluster, defaultNamespace, someDataCenter,
someNotificationId, someClientIp);
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(anotherWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
ResponseEntity<ApolloConfigNotification> response =
(ResponseEntity<ApolloConfigNotification>) deferredResult.getResult();
ApolloConfigNotification notification = response.getBody();
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(defaultNamespace, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
}
示例4: testRegisterFailure
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testRegisterFailure() {
Device device = new Device();
device.setDeviceEUI("123");
device.setEntityType("type");
device.setEntityName("name");
device.setPort(1);
simulateAgentRegisterFailure();
DeferredResult<ResponseEntity<?>> deferredResult = agentRestController.register(device);
verify(mockAgent, times(1)).register(eq(device), any(AgentSuccessCallback.class), any(AgentFailureCallback.class));
ResponseEntity<?> entity = (ResponseEntity<?>) deferredResult.getResult();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
}
示例5: testRegisterWithoutDevice
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testRegisterWithoutDevice() {
simulateAgentRegisterSuccess();
DeferredResult<ResponseEntity<?>> deferredResult = agentRestController.register(null);
verify(mockAgent, times(1)).register(any(), any(AgentSuccessCallback.class), any(AgentFailureCallback.class));
ResponseEntity<?> entity = (ResponseEntity<?>) deferredResult.getResult();
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
示例6: testUnregisterSuccess
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testUnregisterSuccess() {
String deviceEUI = "123";
simulateAgentUnregisterSuccess();
DeferredResult<ResponseEntity<?>> deferredResult = agentRestController.unregister(deviceEUI);
verify(mockAgent, times(1)).unregister(anyString(), any(AgentSuccessCallback.class), any(AgentFailureCallback.class));
ResponseEntity<?> entity = (ResponseEntity<?>) deferredResult.getResult();
assertEquals(HttpStatus.NO_CONTENT, entity.getStatusCode());
}
示例7: testUnregisterFailure
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testUnregisterFailure() {
String deviceEUI = "123";
simulateAgentUnregisterFailure();
DeferredResult<ResponseEntity<?>> deferredResult = agentRestController.unregister(deviceEUI);
verify(mockAgent, times(1)).unregister(anyString(), any(AgentSuccessCallback.class), any(AgentFailureCallback.class));
ResponseEntity<?> entity = (ResponseEntity<?>) deferredResult.getResult();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
}
示例8: testShouldValidateConsumerNameAndEventType
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testShouldValidateConsumerNameAndEventType() {
final Set<EventTypeConsumer> eventTypeConsumerSet = new HashSet<>();
eventTypeConsumerSet.add(new EventTypeConsumer(randomAlphabetic(10), randomAlphabetic(10)));
eventTypeConsumerSet.add(new EventTypeConsumer(randomAlphabetic(10), randomAlphabetic(10)));
when(eventReceiverRegistry.getEventTypeConsumers()).thenReturn(eventTypeConsumerSet);
final DeferredResult<ResponseEntity<?>> deferredResult = eventHandlerController.replay(randomAlphabetic(10),
randomNumeric(2), randomNumeric(2), randomAlphabetic(10), new Random().nextBoolean());
final ResponseEntity<String> responseEntity = (ResponseEntity<String>) deferredResult.getResult();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(responseEntity.getBody()).isEqualTo("Consumer not found.");
}
示例9: testPollNotificationWithMultipleNamespaceWithNotificationIdOutDated
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testPollNotificationWithMultipleNamespaceWithNotificationIdOutDated()
throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, somePublicNamespace);
String yetAnotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, defaultCluster, somePublicNamespace);
long notificationId = someNotificationId + 1;
long yetAnotherNotificationId = someNotificationId;
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey, yetAnotherWatchKey)));
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(
watchKeysMap);
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
when(someReleaseMessage.getId()).thenReturn(notificationId);
when(someReleaseMessage.getMessage()).thenReturn(anotherWatchKey);
ReleaseMessage yetAnotherReleaseMessage = mock(ReleaseMessage.class);
when(yetAnotherReleaseMessage.getId()).thenReturn(yetAnotherNotificationId);
when(yetAnotherReleaseMessage.getMessage()).thenReturn(yetAnotherWatchKey);
when(releaseMessageService
.findLatestReleaseMessagesGroupByMessages(Sets.newHashSet(watchKeysMap.values())))
.thenReturn(Lists.newArrayList(someReleaseMessage, yetAnotherReleaseMessage));
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId,
somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
ResponseEntity<List<ApolloConfigNotification>> result =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(1, result.getBody().size());
assertEquals(somePublicNamespace, result.getBody().get(0).getNamespaceName());
assertEquals(notificationId, result.getBody().get(0).getNotificationId());
ApolloNotificationMessages notificationMessages = result.getBody().get(0).getMessages();
assertEquals(2, notificationMessages.getDetails().size());
assertEquals(notificationId, notificationMessages.get(anotherWatchKey).longValue());
assertEquals(yetAnotherNotificationId, notificationMessages.get(yetAnotherWatchKey).longValue());
}
示例10: testPollNotificationWithMultipleNamespacesAndHandleMessage
import org.springframework.web.context.request.async.DeferredResult; //导入方法依赖的package包/类
@Test
public void testPollNotificationWithMultipleNamespacesAndHandleMessage() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.join(someAppId, someCluster, somePublicNamespace);
Multimap<String, String> watchKeysMap =
assembleMultiMap(defaultNamespace, Lists.newArrayList(someWatchKey));
watchKeysMap
.putAll(assembleMultiMap(somePublicNamespace, Lists.newArrayList(anotherWatchKey)));
when(watchKeysUtil
.assembleAllWatchKeys(someAppId, someCluster,
Sets.newHashSet(defaultNamespace, somePublicNamespace), someDataCenter)).thenReturn(
watchKeysMap);
String notificationAsString =
transformApolloConfigNotificationsToString(defaultNamespace, someNotificationId,
somePublicNamespace, someNotificationId);
DeferredResult<ResponseEntity<List<ApolloConfigNotification>>>
deferredResult = controller
.pollNotification(someAppId, someCluster, notificationAsString, someDataCenter,
someClientIp);
assertEquals(watchKeysMap.size(), deferredResults.size());
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(anotherWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
ResponseEntity<List<ApolloConfigNotification>> response =
(ResponseEntity<List<ApolloConfigNotification>>) deferredResult.getResult();
assertEquals(1, response.getBody().size());
ApolloConfigNotification notification = response.getBody().get(0);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(somePublicNamespace, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
ApolloNotificationMessages notificationMessages = response.getBody().get(0).getMessages();
assertEquals(1, notificationMessages.getDetails().size());
assertEquals(someId, notificationMessages.get(anotherWatchKey).longValue());
}