use of io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback in project joynr by bmwcarit.
the class LocalDiscoveryTest method testMixedLocalCachedRemoteDiscoveryEntries.
@SuppressWarnings("unchecked")
@Test
public void testMixedLocalCachedRemoteDiscoveryEntries() {
String testDomain = "testDomain";
String remoteDomain = "remoteDomain";
Set<String> testDomains = new HashSet<>();
testDomains.add(testDomain);
testDomains.add(remoteDomain);
String interfaceName = testProxy.INTERFACE_NAME;
final Collection<DiscoveryEntry> localDiscoveryEntries = new HashSet<>();
final Collection<DiscoveryEntry> cachedDiscoveryEntries = new HashSet<>();
final List<GlobalDiscoveryEntry> remoteDiscoveryEntries = new ArrayList<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdLocal", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
DiscoveryEntry cachedDiscoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdCached", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
GlobalDiscoveryEntry remoteDiscoveryEntry = CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), remoteDomain, interfaceName, "participantIdRemote", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId"), new MqttAddress());
localDiscoveryEntries.add(discoveryEntry);
cachedDiscoveryEntries.add(cachedDiscoveryEntry);
remoteDiscoveryEntries.add(remoteDiscoveryEntry);
Set<DiscoveryEntryWithMetaInfo> discoveryEntriesWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries);
discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, cachedDiscoveryEntry));
discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteDiscoveryEntry));
when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(localDiscoveryEntries);
when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(cachedDiscoveryEntries);
Mockito.doAnswer(new Answer<Object>() {
@SuppressWarnings("rawtypes")
@Override
public List<GlobalDiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assert (arguments[0] instanceof Callback);
((Callback) arguments[0]).resolve((Object) remoteDiscoveryEntries);
return null;
}
}).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomains, testProxy.class);
final Future<Void> future = new Future<Void>();
ArbitrationStrategyFunction arbitrationStrategyFunction = new ArbitrationStrategyFunction() {
@Override
public Set<DiscoveryEntryWithMetaInfo> select(Map<String, String> parameters, Collection<DiscoveryEntryWithMetaInfo> capabilities) {
return Sets.newHashSet(capabilities);
}
};
DiscoveryQos discoveryQos = new DiscoveryQos(30000, arbitrationStrategyFunction, 0, DiscoveryScope.LOCAL_AND_GLOBAL);
proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
verify(joynrMessagingConnectorFactoryMock).create(anyString(), eq(discoveryEntriesWithMetaInfo), any(MessagingQos.class));
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback in project joynr by bmwcarit.
the class ConsumerApplication method run.
@SuppressWarnings("checkstyle:methodlength")
@Override
public void run() {
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryTimeoutMs(10000);
discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
ProxyBuilder<SystemIntegrationTestProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, SystemIntegrationTestProxy.class);
boolean success = false;
try {
systemIntegrationTestProxy = proxyBuilder.setMessagingQos(new MessagingQos(10000)).setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<SystemIntegrationTestProxy>() {
@Override
public void onProxyCreationFinished(SystemIntegrationTestProxy result) {
LOG.info("proxy created");
proxyCreated.release();
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
LOG.error("error creating proxy");
}
});
try {
if (proxyCreated.tryAcquire(11000, TimeUnit.MILLISECONDS) == false) {
throw new DiscoveryException("proxy not created in time");
}
} catch (InterruptedException e) {
throw new DiscoveryException("proxy not created in time");
}
try {
int addendA = 3333333;
int addendB = 4444444;
Integer sum = systemIntegrationTestProxy.add(addendA, addendB);
if (sum != null && sum == (addendA + addendB)) {
LOG.info("SIT RESULT success: Java consumer -> " + providerDomain + " (" + addendA + " + " + addendB + " = " + sum + ")");
success = true;
}
} catch (Exception e) {
// fallthrough
}
} catch (DiscoveryException | JoynrCommunicationException e) {
// fallthrough
}
if (!success) {
LOG.info("SIT RESULT error: Java consumer -> " + providerDomain);
}
System.exit((success) ? 0 : 1);
}
use of io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback in project joynr by bmwcarit.
the class IltConsumerTest method setupConsumerRuntime.
protected static void setupConsumerRuntime(boolean msgQosCompressed) throws DiscoveryException, JoynrIllegalStateException, InterruptedException {
LOG.info("setupConsumerRuntime: Entering");
final String configFileName = "ilt-consumer-test.settings";
InputStream resourceStream;
try {
resourceStream = new FileInputStream("src/main/resources/" + configFileName);
} catch (IOException e) {
LOG.error("setupConsumerRuntime: Error", e);
resourceStream = null;
}
Properties joynrConfig = new Properties();
try {
if (resourceStream != null) {
LOG.info("setupConsumerRuntime: resources from " + configFileName);
joynrConfig.load(resourceStream);
}
} catch (IOException ex) {
LOG.info("setupConsumerRuntime: not load the configuration file: " + configFileName + ": " + ex);
}
joynrConfig.setProperty(MessagingPropertyKeys.PERSISTENCE_FILE, STATIC_PERSISTENCE_FILE);
joynrConfig.setProperty(AbstractJoynrApplication.PROPERTY_JOYNR_DOMAIN_LOCAL, "inter_language_test_consumer_local_domain");
consumerRuntime = getRuntime(joynrConfig);
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryTimeoutMs(10000);
discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
ProxyBuilder<TestInterfaceProxy> proxyBuilder = consumerRuntime.getProxyBuilder(providerDomain, TestInterfaceProxy.class);
MessagingQos messagingQos = new MessagingQos(10000);
messagingQos.setCompress(msgQosCompressed);
LOG.info("setupConsumerRuntime: msgQosCompression = " + msgQosCompressed);
testInterfaceProxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<TestInterfaceProxy>() {
@Override
public void onProxyCreationFinished(TestInterfaceProxy result) {
LOG.info("proxy created");
proxyCreated.release();
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
LOG.info("error creating proxy");
}
});
if (testInterfaceProxy == null) {
LOG.info("setupConsumerRuntime: proxy = null");
} else {
LOG.info("setupConsumerRuntime: proxy is set != null");
}
// wait until proxy creation is finished or discovery timeout +
// 1 second grace period have passed
proxyCreated.tryAcquire(11000, TimeUnit.MILLISECONDS);
}
use of io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback in project joynr by bmwcarit.
the class LocalDiscoveryTest method testRemoteGlobalDiscoveryEntries.
@SuppressWarnings("unchecked")
@Test
public void testRemoteGlobalDiscoveryEntries() {
String testDomain = "testDomain";
String interfaceName = testProxy.INTERFACE_NAME;
final Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
final List<GlobalDiscoveryEntry> globalDiscoveryEntries = new ArrayList<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
discoveryEntries.add(discoveryEntry);
globalDiscoveryEntries.add(CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, new MqttAddress()));
when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(new HashSet<DiscoveryEntry>());
Mockito.doAnswer(new Answer<Object>() {
@SuppressWarnings("rawtypes")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assert (arguments[0] instanceof Callback);
((Callback) arguments[0]).resolve((Object) globalDiscoveryEntries);
return null;
}
}).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
final Future<Void> future = new Future<Void>();
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
verify(joynrMessagingConnectorFactoryMock).create(anyString(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
assertDiscoveryEntryEqualsCaptured(discoveryEntry);
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback in project joynr by bmwcarit.
the class AccessControllerEnd2EndTest method createProxy.
private testProxy createProxy(JoynrRuntime runtime) {
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
discoveryQos.setDiscoveryTimeoutMs(DISCOVERY_TIMEOUT);
MessagingQos messagingQos = new MessagingQos();
messagingQos.setTtl_ms(MESSAGING_TTL);
final Future<Void> future = new Future<Void>();
testProxy testProxy;
testProxy = runtime.getProxyBuilder(TEST_DOMAIN, testProxy.class).setDiscoveryQos(discoveryQos).setMessagingQos(messagingQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
return testProxy;
}
Aggregations