Search in sources :

Example 56 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException 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);
    }
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) HashSet(java.util.HashSet) MqttAddress(joynr.system.RoutingTypes.MqttAddress) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Callback(io.joynr.proxy.Callback) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(io.joynr.proxy.Future) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 57 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class LocalDiscoveryTest method testLocalDiscoveryEntries.

@Test
public void testLocalDiscoveryEntries() {
    String testDomain = "testDomain";
    String interfaceName = testProxy.INTERFACE_NAME;
    Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    discoveryEntries.add(discoveryEntry);
    when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(discoveryEntries);
    ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
    final Future<Void> future = new Future<Void>();
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_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);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) Future(io.joynr.proxy.Future) ProviderQos(joynr.types.ProviderQos) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class ProxyErrorsTest method setUp.

@Before
public void setUp() {
    // the error callback and NoCompatibleProviderFoundException will each increment the permits.
    // The test will wait until 2 permits are available, or fail in the junit test timeout time.
    waitOnExceptionAndErrorCallbackSemaphore = new Semaphore(-1, true);
    domain = "domain-" + UUID.randomUUID().toString();
    domain2 = "domain2-" + UUID.randomUUID().toString();
    Properties joynrConfig = new Properties();
    joynrConfig.setProperty(MessagingPropertyKeys.CHANNELID, "discoverydirectory_channelid");
    // provider and proxy using same runtime to allow local-only communications
    runtime = getRuntime(joynrConfig);
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    runtime.registerProvider(domain, provider, providerQos);
    runtime.registerProvider(domain2, provider, providerQos);
    discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
    discoveryQos.setDiscoveryTimeoutMs(1000);
    discoveryQos.setRetryIntervalMs(100);
    callback = new ProxyCreatedCallback<ProxyErrorsTest.TestProxyWrongVersion>() {

        @Override
        public void onProxyCreationFinished(TestProxyWrongVersion result) {
            fail("proxy creation should fail with a version exception");
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            // adds 1 of 2 permits to the semaphore. The other is provided when the exception is caught
            waitOnExceptionAndErrorCallbackSemaphore.release();
        }
    };
}
Also used : Semaphore(java.util.concurrent.Semaphore) Properties(java.util.Properties) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderQos(joynr.types.ProviderQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Before(org.junit.Before)

Example 59 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method syncMethodCallReturnsErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncMethodCallReturnsErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.methodWithErrorEnum();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        ApplicationException expected = new ApplicationException(ErrorEnumBase.BASE_ERROR_TYPECOLLECTION);
        assertEquals(expected, e);
    }
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 60 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method asyncMethodCallReturnsExtendedErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void asyncMethodCallReturnsExtendedErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    ApplicationException expected = new ApplicationException(MethodWithErrorEnumExtendedErrorEnum.IMPLICIT_ERROR_TYPECOLLECTION);
    Future<Void> future = proxy.methodWithErrorEnumExtended(callbackWithApplicationExceptionMethodWithErrorEnumExtendedErrorEnum);
    try {
        future.get();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException | InterruptedException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        assertEquals(expected, e);
    }
    verify(callbackWithApplicationExceptionMethodWithErrorEnumExtendedErrorEnum).onFailure((MethodWithErrorEnumExtendedErrorEnum) (expected.getError()));
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) joynr.tests.testProxy(joynr.tests.testProxy) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Aggregations

JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)76 Test (org.junit.Test)41 ApplicationException (joynr.exceptions.ApplicationException)18 joynr.tests.testProxy (joynr.tests.testProxy)16 MessagingQos (io.joynr.messaging.MessagingQos)14 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)13 Callback (io.joynr.proxy.Callback)9 Future (io.joynr.proxy.Future)9 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)9 IOException (java.io.IOException)8 Semaphore (java.util.concurrent.Semaphore)8 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 JoynrException (io.joynr.exceptions.JoynrException)7 DeferredVoid (io.joynr.provider.DeferredVoid)7 HashSet (java.util.HashSet)7 ProviderQos (joynr.types.ProviderQos)7 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5