use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalDiscoveryAggregatorTest method findsProvisionedEntryForMultipleDomains.
@SuppressWarnings("unchecked")
@Test
public void findsProvisionedEntryForMultipleDomains() throws Exception {
discoveryProviderEntries = new DiscoveryEntryWithMetaInfo[] { anotherDiscoveryProviderEntry };
allDomains = new String[] { systemServicesDomain, anotherDomain };
String[] missingDomains = new String[] { anotherDomain };
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Callback<DiscoveryEntryWithMetaInfo[]> callback = (Callback<DiscoveryEntryWithMetaInfo[]>) invocation.getArguments()[0];
callback.onSuccess(discoveryProviderEntries);
return null;
}
}).when(discoveryProxyMock).lookup(any(Callback.class), any(String[].class), anyString(), any(DiscoveryQos.class));
Future<DiscoveryEntryWithMetaInfo[]> discoveryEntriesFuture = localDiscoveryAggregator.lookup(lookupCallback, allDomains, Discovery.INTERFACE_NAME, discoveryQos);
assertNotNull(discoveryEntriesFuture);
DiscoveryEntry[] result = discoveryEntriesFuture.get();
logger.info("Got discovery entries: " + Arrays.toString(result));
assertNotNull(result);
assertEquals(2, result.length);
assertTrue(containsByInterfaceDomain(result, discoveryProviderEntry.getInterfaceName(), discoveryProviderEntry.getDomain()));
assertTrue(containsByInterfaceDomain(result, anotherDiscoveryProviderEntry.getInterfaceName(), anotherDiscoveryProviderEntry.getDomain()));
verify(discoveryProxyMock).lookup(any(Callback.class), eq(missingDomains), eq(Discovery.INTERFACE_NAME), eq(discoveryQos));
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class RequestReplyManagerTest method setUp.
@Before
public void setUp() throws NoSuchMethodException, SecurityException, JsonGenerationException, IOException {
requestCallerFactory = new RequestCallerFactory();
testOneWayRecipientParticipantId = "testOneWayRecipientParticipantId";
testOneWayRecipientDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
testOneWayRecipientDiscoveryEntry.setParticipantId(testOneWayRecipientParticipantId);
testOneWayRecipientDiscoveryEntries = Sets.newHashSet(testOneWayRecipientDiscoveryEntry);
testMessageResponderParticipantId = "testMessageResponderParticipantId";
testMessageResponderDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
testMessageResponderDiscoveryEntry.setParticipantId(testMessageResponderParticipantId);
testSenderParticipantId = "testSenderParticipantId";
testResponderUnregisteredParticipantId = "testResponderUnregisteredParticipantId";
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new JoynrMessageScopeModule());
bind(MessageSender.class).toInstance(messageSenderMock);
bind(MessageRouter.class).toInstance(messageRouterMock);
bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
}
});
objectMapper = injector.getInstance(ObjectMapper.class);
objectMapper.registerSubtypes(Request.class, OneWayRequest.class);
requestReplyManager = injector.getInstance(RequestReplyManager.class);
providerDirectory = injector.getInstance(ProviderDirectory.class);
replyCallerDirectory = injector.getInstance(ReplyCallerDirectory.class);
requestReplyManager = injector.getInstance(RequestReplyManager.class);
// dispatcher.addListener(testOneWayRecipientParticipantId, testListener);
// jsonRequestString1 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
// + payload1 + "\"}}";
// jsonRequestString2 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
// + payload2 + "\"}}";
Object[] params1 = new Object[] { payload1 };
Object[] params2 = new Object[] { payload2 };
// MethodMetaInformation methodMetaInformation = new
// MethodMetaInformation(TestRequestCaller.class.getMethod("respond", new Class[]{ Object.class }));
Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
request1 = new Request(method.getName(), params1, method.getParameterTypes());
request2 = new Request(method.getName(), params2, method.getParameterTypes());
request3 = new Request("unknownMethodName", params2, method.getParameterTypes());
Method fireAndForgetMethod = TestOneWayRecipient.class.getMethod("fireAndForgetMethod", new Class[] { String.class });
oneWay1 = new OneWayRequest(fireAndForgetMethod.getName(), new Object[] { payload1 }, fireAndForgetMethod.getParameterTypes());
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class SubscriptionTimersTest method setUp.
@Before
public void setUp() {
subscriptionEndScheduler = Executors.newScheduledThreadPool(10);
subscriptionManager = new SubscriptionManagerImpl(subscriptionEndScheduler, dispatcher, multicastWildcardRegexFactory);
attributeName = "testAttribute";
fromParticipantId = "fromParticipantId";
toParticipantId = "toParticipantId";
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
future = new Future<String>();
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ArbitrationTest method keywordArbitratorOnChangeSubscriptionsTest.
// Check that the keyword arbitrator will only consider providers that support onChange subscriptions
// when this is requested by the DiscoveryQos
@Test
public void keywordArbitratorOnChangeSubscriptionsTest() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
// Create a capability entry for a provider with the correct keyword but that does not support onChange subscriptions
providerQos.setCustomParameters(qosParameters);
providerQos.setSupportsOnChangeSubscriptions(false);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
// Create a capability entry for a provider with the correct keyword and that also supports onChange subscriptions
ProviderQos providerQos2 = new ProviderQos();
CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
providerQos2.setCustomParameters(qosParameters2);
providerQos2.setSupportsOnChangeSubscriptions(true);
expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "expectedParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
capabilitiesList.add(expectedDiscoveryEntry);
discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
discoveryQos.setProviderMustSupportOnChange(true);
try {
Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
arbitrator.setArbitrationListener(arbitrationCallback);
arbitrator.scheduleArbitration();
assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
} catch (DiscoveryException e) {
fail("A Joyn Arbitration Exception has been thrown");
}
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ArbitrationTest method keyWordArbitratorMissingKeywordTest.
@Test
public void keyWordArbitratorMissingKeywordTest() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "wrongkeyword") };
providerQos.setCustomParameters(qosParameters);
expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
ProviderQos providerQos2 = new ProviderQos();
CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "otherKeyword") };
providerQos2.setCustomParameters(qosParameters2);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
// use minimal timeout to prevent restarting arbitration
int discoveryTimeout = 0;
discoveryQos = new DiscoveryQos(discoveryTimeout, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
try {
Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
arbitrator.setArbitrationListener(arbitrationCallback);
arbitrator.scheduleArbitration();
assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
verify(arbitrationCallback, times(1)).onError(any(Throwable.class));
verify(arbitrationCallback, never()).onSuccess(any(ArbitrationResult.class));
} catch (DiscoveryException e) {
fail("A Joyn Arbitration Exception has been thrown");
}
}
Aggregations