use of joynr.system.RoutingTypes.ChannelAddress 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");
}
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class StaticCapabilitiesProvisioningTest method assertContainsEntryFor.
private void assertContainsEntryFor(Collection<DiscoveryEntry> entries, String interfaceName, String participantId, String url) {
boolean found = false;
for (DiscoveryEntry entry : entries) {
if (entry instanceof GlobalDiscoveryEntry) {
GlobalDiscoveryEntry globalDiscoveryEntry = (GlobalDiscoveryEntry) entry;
if (globalDiscoveryEntry.getInterfaceName().equals(interfaceName) && (participantId == null || participantId.equals(globalDiscoveryEntry.getParticipantId()))) {
if (url != null) {
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
assertTrue(address instanceof ChannelAddress);
assertEquals(url, ((ChannelAddress) address).getMessagingEndpointUrl());
}
found = true;
}
}
}
assertTrue("Couldn't find " + interfaceName + ((participantId == null ? "" : " / " + participantId)) + " in " + entries, found);
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class ServersUtil method createJsonFor.
private static String createJsonFor(String directoriesUrl) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
setObjectMapperOnCapabilitiesUtils(objectMapper);
String channelId = "discoverydirectory_channelid";
String participantId = "capabilitiesdirectory_participantid";
GlobalDiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new ChannelAddress(directoriesUrl, channelId));
String accessParticipantId = "domainaccesscontroller_participantid";
GlobalDiscoveryEntry accessControlEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalDomainAccessController.INTERFACE_NAME, accessParticipantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new InProcessAddress());
List<DiscoveryEntry> entries = new ArrayList<>();
entries.add(discoveryEntry);
entries.add(accessControlEntry);
return objectMapper.writeValueAsString(entries);
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class RoutingProviderImplTest method setUp.
@Before
public void setUp() {
expectedMqttAddress = new MqttAddress("mqtt://test-broker-uri", "test-topic");
expectedMqttAddressString = RoutingTypesUtil.toAddressString(expectedMqttAddress);
expectedChannelAddress = new ChannelAddress("http://test-bounceproxy-url", "test-channelId");
expectedChannelAddressString = RoutingTypesUtil.toAddressString(expectedChannelAddress);
routingProvider = new RoutingProviderImpl(mockMessageRouter, mockGlobalAddressProvider, mockReplyToAddressProvider);
routingProvider.setSubscriptionPublisher(mockRoutingSubscriptionPublisher);
getGlobalAddressOnFulfillmentSemaphore = new Semaphore(0);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
getGlobalAddressOnFulfillmentSemaphore.release();
return null;
}
}).when(mockGlobalAddressPromiseListener).onFulfillment(anyString());
globalAddressChangedSemaphore = new Semaphore(0);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
globalAddressChangedSemaphore.release();
return null;
}
}).when(mockRoutingSubscriptionPublisher).globalAddressChanged(anyString());
getReplyToAddressOnFulfillmentSemaphore = new Semaphore(0);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
getReplyToAddressOnFulfillmentSemaphore.release();
return null;
}
}).when(mockReplyToAddressPromiseListener).onFulfillment(anyString());
replyToAddressChangedSemaphore = new Semaphore(0);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
replyToAddressChangedSemaphore.release();
return null;
}
}).when(mockRoutingSubscriptionPublisher).replyToAddressChanged(anyString());
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class ArbitrationTest method testVersionFilterUsed.
@SuppressWarnings("unchecked")
@Test
public void testVersionFilterUsed() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
String publicKeyId = "publicKeyId";
expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
String[] participantIds = new String[] { "first-participant", "second-participant" };
for (int index = 0; index < participantIds.length; index++) {
DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(index, index), domain, TestInterface.INTERFACE_NAME, participantIds[index], providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
capabilitiesList.add(discoveryEntry);
}
ArbitrationStrategyFunction arbitrationStrategyFunction = mock(ArbitrationStrategyFunction.class);
when(arbitrationStrategyFunction.select(any(Map.class), any(Collection.class))).thenReturn(new HashSet<DiscoveryEntryWithMetaInfo>(capabilitiesList));
discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, arbitrationStrategyFunction, Long.MAX_VALUE);
Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
arbitrator.setArbitrationListener(arbitrationCallback);
arbitrator.scheduleArbitration();
assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
verify(discoveryEntryVersionFilter).filter(interfaceVersion, new HashSet<DiscoveryEntryWithMetaInfo>(capabilitiesList), new HashMap<String, Set<Version>>());
}
Aggregations