use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class LocalDiscoveryTest method assertDiscoveryEntryEqualsCaptured.
private void assertDiscoveryEntryEqualsCaptured(DiscoveryEntry discoveryEntry) {
Set<DiscoveryEntryWithMetaInfo> discoveryEntriesCaptured = discoveryEntryWithMetaInfoArgumentCaptor.getAllValues().get(0);
assertTrue(discoveryEntriesCaptured.size() == 1);
DiscoveryEntryWithMetaInfo discoveryEntryCaptured = discoveryEntriesCaptured.iterator().next();
assertEquals(discoveryEntry.getDomain(), discoveryEntryCaptured.getDomain());
assertEquals(discoveryEntry.getInterfaceName(), discoveryEntryCaptured.getInterfaceName());
assertEquals(discoveryEntry.getParticipantId(), discoveryEntryCaptured.getParticipantId());
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ProxyInvocationHandlerTest method testPartitionsPassedToMulticastSubscription.
@Test
public void testPartitionsPassedToMulticastSubscription() throws NoSuchMethodException, ApplicationException {
ConnectorInvocationHandler connectorInvocationHandler = mock(ConnectorInvocationHandler.class);
when(connectorFactory.create(Mockito.anyString(), Mockito.<ArbitrationResult>any(), Mockito.eq(messagingQos))).thenReturn(connectorInvocationHandler);
MyBroadcastSubscriptionListener broadcastSubscriptionListener = mock(MyBroadcastSubscriptionListener.class);
SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
Method subscribeMethod = MyBroadcastInterface.class.getMethod("subscribeToMyMulticast", MyBroadcastSubscriptionListener.class, SubscriptionQos.class, String[].class);
Object[] args = new Object[] { broadcastSubscriptionListener, subscriptionQos, new String[] { "one", "two", "three" } };
ArbitrationResult arbitrationResult = new ArbitrationResult();
DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
discoveryEntry.setParticipantId("participantId");
arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
proxyInvocationHandler.createConnector(arbitrationResult);
proxyInvocationHandler.invoke(subscribeMethod, args);
ArgumentCaptor<MulticastSubscribeInvocation> captor = ArgumentCaptor.forClass(MulticastSubscribeInvocation.class);
verify(connectorInvocationHandler).executeSubscriptionMethod(captor.capture());
MulticastSubscribeInvocation multicastSubscribeInvocation = captor.getValue();
assertNotNull(multicastSubscribeInvocation);
assertArrayEquals(new String[] { "one", "two", "three" }, multicastSubscribeInvocation.getPartitions());
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class ProxyInvocationHandlerTest method testCallFireAndForgetMethod.
@Test
public void testCallFireAndForgetMethod() throws Throwable {
ConnectorInvocationHandler connectorInvocationHandler = mock(ConnectorInvocationHandler.class);
when(connectorFactory.create(Mockito.anyString(), Mockito.<ArbitrationResult>any(), Mockito.eq(messagingQos))).thenReturn(connectorInvocationHandler);
Method fireAndForgetMethod = TestServiceSync.class.getMethod("callMe", new Class<?>[] { String.class });
Object[] args = new Object[] { "test" };
ArbitrationResult arbitrationResult = new ArbitrationResult();
DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
discoveryEntry.setParticipantId("participantId");
arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
proxyInvocationHandler.createConnector(arbitrationResult);
proxyInvocationHandler.invoke(fireAndForgetMethod, args);
verify(connectorInvocationHandler).executeOneWayMethod(fireAndForgetMethod, args);
}
use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.
the class RpcStubbingTest method setUp.
@Before
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "NPE in test would fail test")
public void setUp() throws JoynrCommunicationException, JoynrSendBufferFullException, JsonGenerationException, JsonMappingException, IOException, JoynrMessageNotSentException {
Deferred<GpsLocation> deferredGpsLocation = new Deferred<GpsLocation>();
deferredGpsLocation.resolve(gpsValue);
when(testMock.returnsGpsLocation()).thenReturn(new Promise<Deferred<GpsLocation>>(deferredGpsLocation));
Deferred<List<GpsLocation>> deferredGpsLocationList = new Deferred<List<GpsLocation>>();
deferredGpsLocationList.resolve(gpsList);
when(testMock.returnsGpsLocationList()).thenReturn(new Promise<Deferred<List<GpsLocation>>>(deferredGpsLocationList));
DeferredVoid deferredVoid = new DeferredVoid();
deferredVoid.resolve();
when(testMock.noParamsNoReturnValue()).thenReturn(new Promise<DeferredVoid>(deferredVoid));
when(testMock.takesTwoSimpleParams(any(Integer.class), any(String.class))).thenReturn(new Promise<DeferredVoid>(deferredVoid));
fromParticipantId = UUID.randomUUID().toString();
toParticipantId = UUID.randomUUID().toString();
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
// required to inject static members of JoynMessagingConnectorFactory
injector = Guice.createInjector(new JoynrPropertiesModule(PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE)), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(RpcUtils.class);
install(new JoynrMessageScopeModule());
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
messagingStubFactory.addBinding(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
}
});
final RequestInterpreter requestInterpreter = injector.getInstance(RequestInterpreter.class);
final RequestCallerFactory requestCallerFactory = injector.getInstance(RequestCallerFactory.class);
when(requestReplyManager.sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), any(Request.class), any(SynchronizedReplyCaller.class), eq(messagingQos))).thenAnswer(new Answer<Reply>() {
@Override
public Reply answer(InvocationOnMock invocation) throws Throwable {
RequestCaller requestCaller = requestCallerFactory.create(testMock);
Object[] args = invocation.getArguments();
Request request = null;
for (Object arg : args) {
if (arg instanceof Request) {
request = (Request) arg;
break;
}
}
final Future<Reply> future = new Future<Reply>();
ProviderCallback<Reply> callback = new ProviderCallback<Reply>() {
@Override
public void onSuccess(Reply result) {
future.onSuccess(result);
}
@Override
public void onFailure(JoynrException error) {
future.onFailure(error);
}
};
requestInterpreter.execute(callback, requestCaller, request);
return future.get();
}
});
JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
connector = joynrMessagingConnectorFactory.create(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), messagingQos);
}
use of joynr.types.DiscoveryEntryWithMetaInfo 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