Search in sources :

Example 1 with ClientServiceNotFoundException

use of com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException in project hazelcast by hazelcast.

the class ClientICacheManagerTest method getCache_when_clientServiceNotFoundExceptionIsThrown_then_illegalStateExceptionIsThrown.

@Test
public void getCache_when_clientServiceNotFoundExceptionIsThrown_then_illegalStateExceptionIsThrown() {
    // when ClientServiceNotFoundException was thrown by hzInstance.getDistributedObject
    // (i.e. cache support is not available on the client-side)
    HazelcastInstance hzInstance = mock(HazelcastInstance.class);
    when(hzInstance.getDistributedObject(anyString(), anyString())).thenThrow(new ClientServiceNotFoundException("mock exception"));
    ClientICacheManager clientCacheManager = new ClientICacheManager(hzInstance);
    // then an IllegalStateException will be thrown by getCache
    thrown.expect(IllegalStateException.class);
    clientCacheManager.getCache("any-cache");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientServiceNotFoundException(com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ClientServiceNotFoundException

use of com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException in project hazelcast by hazelcast.

the class ProxyManager method getOrCreateProxyInternal.

private ClientProxy getOrCreateProxyInternal(@Nonnull String service, @Nonnull String id, boolean remote) {
    checkNotNull(service, "Service name is required!");
    checkNotNull(id, "Object name is required!");
    final ObjectNamespace ns = new DistributedObjectNamespace(service, id);
    ClientProxyFuture proxyFuture = proxies.get(ns);
    if (proxyFuture != null) {
        return proxyFuture.get();
    }
    ClientProxyFactory factory = proxyFactories.get(service);
    if (factory == null) {
        throw new ClientServiceNotFoundException("No factory registered for service: " + service);
    }
    proxyFuture = new ClientProxyFuture();
    ClientProxyFuture current = proxies.putIfAbsent(ns, proxyFuture);
    if (current != null) {
        return current.get();
    }
    try {
        ClientProxy clientProxy = createClientProxy(id, factory);
        if (remote) {
            initialize(clientProxy);
        } else {
            clientProxy.onInitialize();
        }
        proxyFuture.set(clientProxy);
        return clientProxy;
    } catch (Throwable e) {
        proxies.remove(ns);
        proxyFuture.set(e);
        throw rethrow(e);
    }
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ClientServiceNotFoundException(com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Aggregations

ClientServiceNotFoundException (com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 DistributedObjectNamespace (com.hazelcast.internal.services.DistributedObjectNamespace)1 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1