use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalDiscoveryAggregator method lookup.
@Override
public Future<DiscoveryEntryWithMetaInfo[]> lookup(final Callback<DiscoveryEntryWithMetaInfo[]> callback, String[] domains, String interfaceName, DiscoveryQos discoveryQos) {
final Set<DiscoveryEntryWithMetaInfo> discoveryEntries = new HashSet<>();
Set<String> missingDomains = new HashSet<>();
for (String domain : domains) {
if (provisionedDiscoveryEntries.containsKey(domain + interfaceName)) {
DiscoveryEntryWithMetaInfo discoveryEntry = provisionedDiscoveryEntries.get(domain + interfaceName);
discoveryEntries.add(discoveryEntry);
} else {
missingDomains.add(domain);
}
}
logger.trace("Found locally provisioned discovery entries: {}", discoveryEntries);
final Future<DiscoveryEntryWithMetaInfo[]> discoveryEntryFuture = new Future<>();
if (!missingDomains.isEmpty()) {
logger.trace("Did not find entries for the following domains: {}", missingDomains);
Callback<DiscoveryEntryWithMetaInfo[]> newCallback = new Callback<DiscoveryEntryWithMetaInfo[]>() {
@Override
public void onFailure(JoynrRuntimeException error) {
callback.onFailure(error);
discoveryEntryFuture.onFailure(error);
}
@Override
public void onSuccess(DiscoveryEntryWithMetaInfo[] entries) {
assert entries != null : "Entries must not be null.";
logger.trace("Globally found entries for missing domains: {}", Arrays.toString(entries));
Collections.addAll(discoveryEntries, entries);
resolveDiscoveryEntriesFutureWithEntries(discoveryEntryFuture, discoveryEntries, callback);
}
};
String[] missingDomainsArray = new String[missingDomains.size()];
missingDomains.toArray(missingDomainsArray);
getDiscoveryProxy(discoveryQos.getDiscoveryTimeout()).lookup(newCallback, missingDomainsArray, interfaceName, discoveryQos);
} else {
resolveDiscoveryEntriesFutureWithEntries(discoveryEntryFuture, discoveryEntries, callback);
}
return discoveryEntryFuture;
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ConnectorTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
fromParticipantId = "fromParticipantId";
toParticipantId = "toParticipantId";
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
toDiscoveryEntries = Sets.newHashSet(toDiscoveryEntry);
qosSettings = new MessagingQos();
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ProxyInvocationHandlerTest method callProxyInvocationHandlerSyncFromMultipleThreadsTest.
@Test(timeout = 3000)
public void callProxyInvocationHandlerSyncFromMultipleThreadsTest() throws Throwable {
Future<?> call1 = threadPool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Object result = null;
try {
result = proxyInvocationHandler.invoke(TestSyncInterface.class.getDeclaredMethod("testMethod", new Class<?>[] {}), new Object[] {});
} catch (Exception e) {
}
return result;
}
});
Future<?> call2 = threadPool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Object result = null;
try {
result = proxyInvocationHandler.invoke(TestSyncInterface.class.getDeclaredMethod("testMethod", new Class<?>[] {}), new Object[] {});
} catch (Exception e) {
}
return result;
}
});
ArbitrationResult arbitrationResult = new ArbitrationResult();
DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
discoveryEntry.setParticipantId("participantId");
arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
proxyInvocationHandler.createConnector(arbitrationResult);
// if the bug that causes one thread to hang in arbitration exists, one
// of these calls will never return, causing the test to timeout and fail
call1.get();
call2.get();
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ProxyTest method setUp.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
navigationProxyCreatedSemaphore = new Semaphore(0);
navigationProxyCreatedCallback = new ProxyCreatedCallback<NavigationProxy>() {
@Override
public void onProxyCreationFinished(NavigationProxy result) {
navigationProxyCreatedSemaphore.release();
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
fail("Navigation proxy creation failed: " + error);
}
};
testInterfaceProxyCreatedSemaphore = new Semaphore(0);
testInterfaceProxyCreatedCallback = new ProxyCreatedCallback<TestInterface>() {
@Override
public void onProxyCreationFinished(TestInterface result) {
testInterfaceProxyCreatedSemaphore.release();
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
fail("TestInterface proxy creation failed: " + error);
}
};
domain = "TestDomain";
fromParticipantId = "ProxyTestFromParticipantId";
toParticipantId = "ProxyTestToParticipantId";
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, toParticipantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + ONE_MINUTE_IN_MS, "publicKeyId", true);
toDiscoveryEntries = new HashSet<DiscoveryEntryWithMetaInfo>();
toDiscoveryEntries.add(toDiscoveryEntry);
MockitoAnnotations.initMocks(this);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(RpcUtils.class);
bind(ReplyCallerDirectory.class).toInstance(replyCallerDirectory);
bind(RequestReplyManager.class).toInstance(requestReplyManager);
bind(SubscriptionManager.class).toInstance(subscriptionManager);
bind(MessageRouter.class).toInstance(messageRouter);
bind(RoutingTable.class).toInstance(routingTable);
install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
}
@Provides
@Singleton
@Named(SystemServicesSettings.PROPERTY_DISPATCHER_ADDRESS)
Address getDispatcherAddress() {
return new InProcessAddress();
}
});
proxyBuilderFactory = new ProxyBuilderFactoryImpl(localDiscoveryAggregator, injector.getInstance(ProxyInvocationHandlerFactory.class), MAX_TTL_MS, DISCOVERY_TIMEOUT_MS, RETRY_INTERVAL_MS);
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
DiscoveryEntryWithMetaInfo[] fakeCapabilitiesResult = { toDiscoveryEntry };
((Callback) args[0]).resolve((Object) fakeCapabilitiesResult);
return null;
}
}).when(localDiscoveryAggregator).lookup(Mockito.<Callback>any(), Mockito.<String[]>any(), Mockito.<String>any(), Mockito.<joynr.types.DiscoveryQos>any());
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
AttributeSubscribeInvocation request = (AttributeSubscribeInvocation) args[2];
if (request.getSubscriptionId() == null) {
request.setSubscriptionId(UUID.randomUUID().toString());
}
request.getFuture().resolve(request.getSubscriptionId());
return null;
}
}).when(subscriptionManager).registerAttributeSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(AttributeSubscribeInvocation.class));
Mockito.doAnswer(new // TODO simulate resolve here ! subscription reply bastern ... handle subscriptionreply ausführen..
Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
BroadcastSubscribeInvocation request = (BroadcastSubscribeInvocation) args[2];
if (request.getSubscriptionId() == null) {
request.setSubscriptionId(UUID.randomUUID().toString());
}
request.getFuture().resolve(request.getSubscriptionId());
return null;
}
}).when(subscriptionManager).registerBroadcastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(BroadcastSubscribeInvocation.class));
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
MulticastSubscribeInvocation request = (MulticastSubscribeInvocation) args[2];
if (request.getSubscriptionId() == null) {
request.setSubscriptionId(UUID.randomUUID().toString());
}
request.getFuture().resolve(request.getSubscriptionId());
return null;
}
}).when(subscriptionManager).registerMulticastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(MulticastSubscribeInvocation.class));
discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
messagingQos = new MessagingQos();
doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {
@Override
public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
}
}).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
Field discoveryEntryVersionFilterField = ArbitratorFactory.class.getDeclaredField("discoveryEntryVersionFilter");
discoveryEntryVersionFilterField.setAccessible(true);
discoveryEntryVersionFilterField.set(ArbitratorFactory.class, discoveryEntryVersionFilter);
doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {
@Override
public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
}
}).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
Field schedulerField = ArbitratorFactory.class.getDeclaredField("scheduler");
schedulerField.setAccessible(true);
String name = "TEST.joynr.scheduler.arbitration.arbitratorRunnable";
ThreadFactory joynrThreadFactory = new JoynrThreadFactory(name, true);
scheduler = Executors.newSingleThreadScheduledExecutor(joynrThreadFactory);
schedulerField.set(ArbitratorFactory.class, scheduler);
Field shutdownNotifierField = ArbitratorFactory.class.getDeclaredField("shutdownNotifier");
shutdownNotifierField.setAccessible(true);
shutdownNotifierField.set(ArbitratorFactory.class, shutdownNotifier);
ArbitratorFactory.start();
verify(shutdownNotifier).registerForShutdown(any(ShutdownListener.class));
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalDiscoveryAggregatorTest method setUp.
@Before
public void setUp() {
systemServicesDomain = "test.system.service.domain";
anotherDomain = "anotherDomain";
discoveryProviderParticipantId = "test.discovery.provider.participant";
when(proxyBuilderFactory.get(anyString(), eq(DiscoveryProxy.class))).thenReturn(proxyBuilder);
when(proxyBuilder.build()).thenReturn(discoveryProxyMock);
when(proxyBuilder.setMessagingQos(any(MessagingQos.class))).thenReturn(proxyBuilder);
localDiscoveryAggregator = new LocalDiscoveryAggregator(systemServicesDomain, discoveryProviderParticipantId, "routingProviderParticipantId", proxyBuilderFactory);
localDiscoveryAggregator.forceQueryOfDiscoveryProxy();
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.LOCAL);
discoveryProviderEntry = new DiscoveryEntryWithMetaInfo(new Version(0, 1), systemServicesDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, true);
anotherDiscoveryProviderEntry = new DiscoveryEntryWithMetaInfo(new Version(0, 0), anotherDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, true);
}
Aggregations