Search in sources :

Example 6 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method testSimpleBroadcast.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void testSimpleBroadcast() throws InterruptedException, JoynrWaitExpiredException, JoynrRuntimeException, ApplicationException {
    final Semaphore broadcastReceived = new Semaphore(0);
    final GpsLocation gpsLocation = new GpsLocation(1.0, 2.0, 3.0, GpsFixEnum.MODE3D, 4.0, 5.0, 6.0, 7.0, 8L, 9L, 10);
    final Float currentSpeed = Float.MAX_VALUE;
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    Future<String> subscriptionIdFuture = proxy.subscribeToLocationUpdateWithSpeedBroadcast(new LocationUpdateWithSpeedBroadcastAdapter() {

        @Override
        public void onReceive(GpsLocation receivedGpsLocation, Float receivedCurrentSpeed) {
            assertEquals(gpsLocation, receivedGpsLocation);
            assertEquals(currentSpeed, receivedCurrentSpeed);
            broadcastReceived.release();
        }
    }, new MulticastSubscriptionQos());
    // wait to allow the subscription request to arrive at the provider
    subscriptionIdFuture.get();
    provider.fireLocationUpdateWithSpeed(gpsLocation, currentSpeed);
    broadcastReceived.acquire();
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) GpsLocation(joynr.types.Localisation.GpsLocation) Semaphore(java.util.concurrent.Semaphore) LocationUpdateWithSpeedBroadcastAdapter(joynr.tests.testBroadcastInterface.LocationUpdateWithSpeedBroadcastAdapter) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) Test(org.junit.Test)

Example 7 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method registerSubscriptionForComplexDatatype.

@SuppressWarnings("unchecked")
@Test
public void registerSubscriptionForComplexDatatype() throws InterruptedException, ApplicationException {
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<GpsLocation> gpsListener = mock(AttributeSubscriptionListener.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            onReceiveSemaphore.release();
            return null;
        }
    }).when(gpsListener).onReceive(eq(provider.getComplexTestAttributeSync()));
    int periods = 2;
    long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(500);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToComplexTestAttribute(gpsListener, subscriptionQos);
    assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
    verify(gpsListener, times(0)).onError(null);
    proxy.unsubscribeFromComplexTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) GpsLocation(joynr.types.Localisation.GpsLocation) Semaphore(java.util.concurrent.Semaphore) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 8 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationNotSentWhenFiltersFail.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationNotSentWhenFiltersFail() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters();
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setPublicationTtlMs(ttl);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(SUBSCRIPTION_ID, "subscribedToName", filterParameters, qos);
    when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
    when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
    GpsLocation eventValue = new GpsLocation();
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateSelectiveBroadcastFilter filterTrue = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filterTrue.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filterTrue);
    testLocationUpdateSelectiveBroadcastFilter filterFalse = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filterFalse.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(false);
    filters.add(filterFalse);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, eventValue);
    verify(dispatcher, never()).sendSubscriptionPublication(any(String.class), any(Set.class), any(SubscriptionPublication.class), any(MessagingQos.class));
}
Also used : Set(java.util.Set) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Matchers.anyString(org.mockito.Matchers.anyString) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Test(org.junit.Test)

Example 9 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationCallsAllFiltersWithFilterParametersAndValues.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationCallsAllFiltersWithFilterParametersAndValues() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters();
    filterParameters.setCountry("Germany");
    filterParameters.setStartTime("4:00");
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setPublicationTtlMs(ttl);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(SUBSCRIPTION_ID, "subscribedToName", filterParameters, qos);
    when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
    when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
    GpsLocation eventValue = new GpsLocation();
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateSelectiveBroadcastFilter filter1 = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filter1.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filter1);
    testLocationUpdateSelectiveBroadcastFilter filter2 = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filter2.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filter2);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, eventValue);
    ArgumentCaptor<SubscriptionPublication> publicationCaptured = ArgumentCaptor.forClass(SubscriptionPublication.class);
    ArgumentCaptor<MessagingQos> qosCaptured = ArgumentCaptor.forClass(MessagingQos.class);
    verify(dispatcher).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), publicationCaptured.capture(), qosCaptured.capture());
    verify(filter1).filter(eventValue, filterParameters);
    verify(filter2).filter(eventValue, filterParameters);
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Matchers.anyString(org.mockito.Matchers.anyString) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Test(org.junit.Test)

Example 10 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class SerializationTest method serialzeAndDeserializeTestGpsLocation.

@Test
public void serialzeAndDeserializeTestGpsLocation() throws JsonGenerationException, JsonMappingException, IOException {
    GpsLocation gps1 = new GpsLocation();
    gps1.setGpsFix(GpsFixEnum.MODE3D);
    gps1.setLongitude(1.1);
    gps1.setLatitude(2.2);
    gps1.setAltitude(3.3);
    gps1.setTime(17);
    String serializedContent = objectMapper.writeValueAsString(gps1);
    LOG.debug("Serialized TestGpsLocation={}", serializedContent);
    assertTrue(serializedContent.startsWith("{\"_typeName\""));
    GpsLocation gps2 = objectMapper.readValue(serializedContent, GpsLocation.class);
    Assert.assertEquals(gps1, gps2);
}
Also used : GpsLocation(joynr.types.Localisation.GpsLocation) Test(org.junit.Test)

Aggregations

GpsLocation (joynr.types.Localisation.GpsLocation)22 Test (org.junit.Test)18 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)9 Semaphore (java.util.concurrent.Semaphore)7 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)6 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 MessagingQos (io.joynr.messaging.MessagingQos)5 ArrayList (java.util.ArrayList)5 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)5 SubscriptionRequest (joynr.SubscriptionRequest)5 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)4 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)4 SubscriptionPublication (joynr.SubscriptionPublication)4 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)4 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 joynr.tests.testProxy (joynr.tests.testProxy)3 Ignore (org.junit.Ignore)3 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2