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();
}
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));
}
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));
}
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);
}
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);
}
Aggregations