use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class LibJoynrMessageRouter method addMulticastReceiver.
@Override
public void addMulticastReceiver(final String multicastId, final String subscriberParticipantId, final String providerParticipantId) {
super.addMulticastReceiver(multicastId, subscriberParticipantId, providerParticipantId);
DeferrableRegistration registerWithParent = new DeferrableRegistration() {
@Override
public void register() {
Address providerAddress = routingTable.get(providerParticipantId);
if (providerAddress == null || !(providerAddress instanceof InProcessAddress)) {
parentRouter.addMulticastReceiver(multicastId, subscriberParticipantId, providerParticipantId);
}
}
};
if (parentRouter != null) {
registerWithParent.register();
} else {
synchronized (deferredMulticastRegistrations) {
deferredMulticastRegistrations.put(multicastId + subscriberParticipantId + providerParticipantId, registerWithParent);
}
}
}
use of joynr.system.RoutingTypes.Address 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.system.RoutingTypes.Address in project joynr by bmwcarit.
the class CapabilitiesUtilsTest method testGetMqttAddressFromGlobalDiscoveryEntry.
@Test
public void testGetMqttAddressFromGlobalDiscoveryEntry() {
GlobalDiscoveryEntry globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(0, 0), "domain", "interfaceName", "participantId", new ProviderQos(), 0L, 0L, "publicKeyId", "{\"_typeName\":\"joynr.system.RoutingTypes.MqttAddress\",\"brokerUri\":\"tcp://broker:1883\",\"topic\":\"topic\"}");
Address result = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
assertTrue(result instanceof MqttAddress);
assertEquals("tcp://broker:1883", ((MqttAddress) result).getBrokerUri());
assertEquals("topic", ((MqttAddress) result).getTopic());
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class CapabilitiesUtilsTest method testCreateNewGlobalDiscoveryEntry.
@Test
public void testCreateNewGlobalDiscoveryEntry() {
Version version = new Version(0, 0);
String domain = "domain";
String interfaceName = "interfaceName";
String participantId = "participantId";
String publicKeyId = "publicKeyId";
Address mqttAddress = new MqttAddress("tcp://broker:1883", "topic");
ProviderQos providerQos = new ProviderQos();
GlobalDiscoveryEntry result = CapabilityUtils.newGlobalDiscoveryEntry(version, domain, interfaceName, participantId, providerQos, 0L, 0L, publicKeyId, mqttAddress);
assertNotNull(result);
assertEquals(version, result.getProviderVersion());
assertEquals(domain, result.getDomain());
assertEquals(interfaceName, result.getInterfaceName());
assertEquals(participantId, result.getParticipantId());
assertEquals(providerQos, result.getQos());
assertEquals((Long) 0L, result.getLastSeenDateMs());
assertEquals((Long) 0L, result.getExpiryDateMs());
assertEquals(publicKeyId, result.getPublicKeyId());
assertEquals("{\"_typeName\":\"joynr.system.RoutingTypes.MqttAddress\",\"brokerUri\":\"tcp://broker:1883\",\"topic\":\"topic\"}", result.getAddress());
}
use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.
the class LegacyCapabilitiesProvisioningTest method testMqttAddressGeneratedCorrectly.
@Test
public void testMqttAddressGeneratedCorrectly() {
LegacyCapabilitiesProvisioning.LegacyProvisioningPropertiesHolder propertiesHolder = new LegacyCapabilitiesProvisioning.LegacyProvisioningPropertiesHolder("tcp://localhost:1883", "tcp://localhost:1883", "channel_id", "discovery_domain", "capabilities_domain", "capdir_channel_id", "domain_access_ctrl_participant_id", "domain_access_ctrl_channel_id");
LegacyCapabilitiesProvisioning subject = new LegacyCapabilitiesProvisioning(propertiesHolder);
Address address = subject.getAddressForInterface(GlobalCapabilitiesDirectory.class);
assertTrue(address instanceof MqttAddress);
MqttAddress globalCapabilitiesAddress = (MqttAddress) address;
assertEquals("tcp://localhost:1883", globalCapabilitiesAddress.getBrokerUri());
assertEquals("capdir_channel_id", globalCapabilitiesAddress.getTopic());
}
Aggregations