use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.
the class SerializationTest method serializeBroadcastSubscriptionRequest.
@Test
public void serializeBroadcastSubscriptionRequest() throws JsonGenerationException, JsonMappingException, IOException {
String subscriptionId = "1234";
String subscribedToName = "myEvent";
testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters();
filterParameters.setCountry("Germany");
filterParameters.setStartTime("4:00");
OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(0).setValidityMs(60000).setPublicationTtlMs(1000);
BroadcastSubscriptionRequest broadcastSubscription = new BroadcastSubscriptionRequest(subscriptionId, subscribedToName, filterParameters, qos);
String writeValueAsString = objectMapper.writeValueAsString(broadcastSubscription);
System.out.println(writeValueAsString);
BroadcastSubscriptionRequest receivedbroadcastSubscription = objectMapper.readValue(writeValueAsString, BroadcastSubscriptionRequest.class);
Assert.assertEquals(broadcastSubscription, receivedbroadcastSubscription);
}
use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.
the class AbstractBroadcastEnd2EndTest method subscribeToSelectiveBroadcast_FilterTrue.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToSelectiveBroadcast_FilterTrue() throws InterruptedException {
final Semaphore broadcastReceived = new Semaphore(0);
final LocationUpdateSelectiveBroadcastFilterParameters testFilterParameters = new LocationUpdateSelectiveBroadcastFilterParameters();
testFilterParameters.setCountry("Germany");
testFilterParameters.setStartTime("4.00 pm");
testLocationUpdateSelectiveBroadcastFilter filter1 = new testLocationUpdateSelectiveBroadcastFilter() {
@Override
public boolean filter(GpsLocation location, LocationUpdateSelectiveBroadcastFilterParameters filterParameters) {
assertEquals(testFilterParameters, filterParameters);
return true;
}
};
testLocationUpdateSelectiveBroadcastFilter filter2 = new testLocationUpdateSelectiveBroadcastFilter() {
@Override
public boolean filter(GpsLocation location, LocationUpdateSelectiveBroadcastFilterParameters filterParameters) {
assertEquals(testFilterParameters, filterParameters);
return true;
}
};
getSubscriptionTestsPublisher().addBroadcastFilter(filter1);
getSubscriptionTestsPublisher().addBroadcastFilter(filter2);
OnChangeSubscriptionQos subscriptionQos = createDefaultOnChangeSubscriptionQos();
proxy.subscribeToLocationUpdateSelectiveBroadcast(new testBroadcastInterface.LocationUpdateSelectiveBroadcastAdapter() {
@Override
public void onReceive(GpsLocation location) {
assertEquals(expectedLocation, location);
broadcastReceived.release();
}
}, subscriptionQos, testFilterParameters);
Thread.sleep(300);
provider.fireLocationUpdateSelective(expectedLocation);
broadcastReceived.acquire();
}
use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.
the class AbstractLocalCommunicationTest method registerSubscriptionOnChangeAndReceiveUpdatesForLongTime.
/* This is a manual test that subscribes for 30 seconds, and checks if all subscriptions arrive. In this case,
* the test expect publication in case of value change
*/
@Test
@Ignore
public void registerSubscriptionOnChangeAndReceiveUpdatesForLongTime() throws InterruptedException {
final int times = 5;
final int initialValue = 42;
int period = lengthInMS / times;
provider.ATTRIBUTEWITHCAPITALLETTERSChanged(initialValue);
OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
subscriptionQos.setMinIntervalMs(lengthInMS / 4).setValidityMs(lengthInMS).setPublicationTtlMs(lengthInMS / 4);
new Timer().scheduleAtFixedRate(new TimerTask() {
int value = initialValue;
@Override
public void run() {
value++;
if (value < initialValue + times) {
provider.ATTRIBUTEWITHCAPITALLETTERSChanged(value);
}
}
}, period, period);
proxy.subscribeToATTRIBUTEWITHCAPITALLETTERS(listener, subscriptionQos);
// - (System.currentTimeMillis() - currentTime));
Thread.sleep(lengthInMS + 100);
verify(listener, times(0)).onError(null);
verify(listener, times(times)).onReceive(anyInt());
// TODO verify publications shipped correct data
for (int i = 42; i < 42 + times; i++) {
verify(listener, times(1)).onReceive(eq(i));
}
verifyNoMoreInteractions(listener);
}
use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.
the class TtlUpliftTest method testAttributeSubscriptionWithTtlUpliftWithLargeExpiryDate.
@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void testAttributeSubscriptionWithTtlUpliftWithLargeExpiryDate() throws Exception {
long validityMs = 300;
long publicationTtlMs = 1000;
OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
qos.setMinIntervalMs(0);
qos.setExpiryDateMs(LARGE_EXPIRY_DATE_MS - SUBSCRIPTION_UPLIFT_MS + 1);
qos.setPublicationTtlMs(publicationTtlMs);
long expectedSubscriptionReplyTtl = qos.getExpiryDateMs() - System.currentTimeMillis();
long expectedPublicationTtlMs = publicationTtlMs;
testAttributeSubscriptionWithTtlUplift(qos, validityMs, expectedSubscriptionReplyTtl, expectedPublicationTtlMs);
publicationManagerWithTtlUplift.attributeValueChanged(SUBSCRIPTION_ID, valueToPublish);
verify(dispatcher, timeout(300).times(1)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), argThat(new MessagingQosMatcher(expectedPublicationTtlMs)));
}
use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.
the class PublicationManagerTest method broadcastPublicationIsSentWhenFiltersPass.
@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationIsSentWhenFiltersPass() throws Exception {
publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
long minInterval_ms = 0;
long ttl = 1000;
testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters();
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 location = new GpsLocation(1.0, 2.0, 3.0, GpsFixEnum.MODE2D, 4.0, 5.0, 6.0, 7.0, 9l, 10l, 11);
float speed = 100;
ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
testLocationUpdateWithSpeedSelectiveBroadcastFilter filterTrue = mock(testLocationUpdateWithSpeedSelectiveBroadcastFilter.class);
when(filterTrue.filter(any(GpsLocation.class), any(Float.class), any(testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters.class))).thenReturn(true);
filters.add(filterTrue);
publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, location, speed);
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());
List<?> response = (List<?>) publicationCaptured.getValue().getResponse();
assertEquals(location, response.get(0));
assertEquals(speed, response.get(1));
}
Aggregations