Search in sources :

Example 1 with CustomParameter

use of joynr.types.CustomParameter in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    channelAddress = new ChannelAddress(TEST_URL, "testChannelId");
    ObjectMapper objectMapper = new ObjectMapper();
    channelAddressSerialized = objectMapper.writeValueAsString(channelAddress);
    Field objectMapperField = CapabilityUtils.class.getDeclaredField("objectMapper");
    objectMapperField.setAccessible(true);
    objectMapperField.set(CapabilityUtils.class, objectMapper);
    Answer<Void> answer = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            ((Callback<Void>) args[0]).onSuccess(null);
            return null;
        }
    };
    doAnswer(answer).when(globalCapabilitiesClient).add(any(Callback.class), any(GlobalDiscoveryEntry.class));
    String discoveryDirectoriesDomain = "io.joynr";
    String capabilitiesDirectoryParticipantId = "capDir_participantId";
    String capabiltitiesDirectoryChannelId = "dirchannelId";
    String domainAccessControllerParticipantId = "domainAccessControllerParticipantId";
    String domainAccessControllerChannelId = "domainAccessControllerChannelId";
    DiscoveryEntry globalCapabilitiesDirectoryDiscoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), discoveryDirectoriesDomain, GlobalCapabilitiesDirectory.INTERFACE_NAME, capabilitiesDirectoryParticipantId, new ProviderQos(), System.currentTimeMillis(), expiryDateMs, domainAccessControllerChannelId, new ChannelAddress(TEST_URL, capabiltitiesDirectoryChannelId));
    DiscoveryEntry domainAccessControllerDiscoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), discoveryDirectoriesDomain, GlobalDomainAccessController.INTERFACE_NAME, domainAccessControllerParticipantId, new ProviderQos(), System.currentTimeMillis(), expiryDateMs, domainAccessControllerChannelId, new ChannelAddress(TEST_URL, domainAccessControllerChannelId));
    when(capabilitiesProvisioning.getDiscoveryEntries()).thenReturn(Sets.newHashSet(globalCapabilitiesDirectoryDiscoveryEntry, domainAccessControllerDiscoveryEntry));
    // use default freshnessUpdateIntervalMs: 3600000ms (1h)
    localCapabilitiesDirectory = new LocalCapabilitiesDirectoryImpl(capabilitiesProvisioning, globalAddressProvider, localDiscoveryEntryStoreMock, globalDiscoveryEntryCacheMock, messageRouter, globalCapabilitiesClient, expiredDiscoveryEntryCacheCleaner, 3600000, capabilitiesFreshnessUpdateExecutor, defaultDiscoveryRetryIntervalMs, shutdownNotifier);
    verify(expiredDiscoveryEntryCacheCleaner).scheduleCleanUpForCaches(Mockito.<ExpiredDiscoveryEntryCacheCleaner.CleanupAction>any(), argThat(new DiscoveryEntryStoreVarargMatcher(globalDiscoveryEntryCacheMock, localDiscoveryEntryStoreMock)));
    verify(capabilitiesFreshnessUpdateExecutor).scheduleAtFixedRate(runnableCaptor.capture(), anyLong(), anyLong(), eq(TimeUnit.MILLISECONDS));
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] parameterList = { new CustomParameter("key1", "value1"), new CustomParameter("key2", "value2") };
    providerQos.setCustomParameters(parameterList);
    String participantId = "testParticipantId";
    String domain = "domain";
    discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Matchers.anyString(org.mockito.Matchers.anyString) Field(java.lang.reflect.Field) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DeferredVoid(io.joynr.provider.DeferredVoid) CustomParameter(joynr.types.CustomParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 2 with CustomParameter

use of joynr.types.CustomParameter in project joynr by bmwcarit.

the class BroadcastEnd2EndTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    final int port = ServletUtil.findFreePort();
    webSocketConfig = new Properties();
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, "localhost");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "" + port);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
    providerQos = new ProviderQos(new CustomParameter[0], System.currentTimeMillis(), ProviderScope.LOCAL, false);
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE, DiscoveryScope.LOCAL_ONLY);
    // init websocket properties before libjoynr runtimes are created
    super.setUp();
// Uncomment to log the verbose android logs to stdout
// ShadowLog.stream = System.out;
}
Also used : Properties(java.util.Properties) CustomParameter(joynr.types.CustomParameter) ProviderQos(joynr.types.ProviderQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Before(org.junit.Before)

Example 3 with CustomParameter

use of joynr.types.CustomParameter in project joynr by bmwcarit.

the class ProviderProxyEnd2EndTest method baseSetup.

@Override
@Before
public void baseSetup() throws Exception {
    final int port = ServletUtil.findFreePort();
    webSocketConfig = new Properties();
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, "localhost");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "" + port);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
    testProviderQos = new ProviderQos(new CustomParameter[0], System.currentTimeMillis(), ProviderScope.LOCAL, false);
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE, DiscoveryScope.LOCAL_ONLY);
    // init websocket properties before libjoynr runtimes are created
    super.baseSetup();
// Uncomment to log the verbose android logs to stdout
// ShadowLog.stream = System.out;
}
Also used : Properties(java.util.Properties) CustomParameter(joynr.types.CustomParameter) ProviderQos(joynr.types.ProviderQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Before(org.junit.Before)

Example 4 with CustomParameter

use of joynr.types.CustomParameter in project joynr by bmwcarit.

the class SubscriptionEnd2EndTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    final int port = ServletUtil.findFreePort();
    webSocketConfig = new Properties();
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, "localhost");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "" + port);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
    providerQos = new ProviderQos(new CustomParameter[0], System.currentTimeMillis(), ProviderScope.LOCAL, false);
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE, DiscoveryScope.LOCAL_ONLY);
    super.setUp();
// Uncomment to log the verbose android logs to stdout
// ShadowLog.stream = System.out;
}
Also used : Properties(java.util.Properties) CustomParameter(joynr.types.CustomParameter) ProviderQos(joynr.types.ProviderQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Before(org.junit.Before)

Example 5 with CustomParameter

use of joynr.types.CustomParameter 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");
    }
}
Also used : Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CustomParameter(joynr.types.CustomParameter) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

CustomParameter (joynr.types.CustomParameter)8 ProviderQos (joynr.types.ProviderQos)7 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 Version (joynr.types.Version)4 Before (org.junit.Before)4 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)3 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DeferredVoid (io.joynr.provider.DeferredVoid)1 Callback (io.joynr.proxy.Callback)1 Field (java.lang.reflect.Field)1 DiscoveryEntry (joynr.types.DiscoveryEntry)1 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1