use of org.apache.ignite.internal.processors.service.inner.MyService in project ignite by apache.
the class GridServiceProxyNodeStopSelfTest method testProxyHashCode.
/**
* @throws Exception If failed.
*/
@Test
public void testProxyHashCode() throws Exception {
Ignite server = startGrid("server");
server.services().deployClusterSingleton("my-service", MyServiceFactory.create());
Ignite client = startClientGrid("client");
final MyService proxy = client.services().serviceProxy("my-service", MyService.class, false);
assertEquals("GridServiceProxy [name=my-service, sticky=false]", proxy.toString());
assertEquals(42, proxy.hello());
assertEquals(MyService.HASH, proxy.hashCode(null));
MyService proxy0 = proxy;
assertTrue(proxy0.equals(proxy));
proxy0 = client.services().serviceProxy("my-service", MyService.class, false);
assertFalse(proxy0.equals(proxy));
int hash = proxy.hashCode();
assertFalse(hash == MyService.HASH);
client.close();
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
proxy.hello();
return null;
}
}, IllegalStateException.class, null);
int hash0 = proxy.hashCode();
assertFalse(hash0 == MyService.HASH);
assertEquals(hash, hash0);
}
use of org.apache.ignite.internal.processors.service.inner.MyService in project ignite by apache.
the class ServiceDeploymentOnClientDisconnectTest method testServiceDeploymentExchangeProcessingOnReconnect.
/**
* @throws Exception In case of an error.
*/
@Test
public void testServiceDeploymentExchangeProcessingOnReconnect() throws Exception {
IgniteEx client = client();
IgniteFuture fut = client.services().deployNodeSingletonAsync("testService1", new LongInitializedTestService(10_000L));
client.services().deployNodeSingletonAsync("testService2", new LongInitializedTestService(10_000L));
server().close();
IgniteFuture reconnectFut = null;
try {
fut.get();
fail("Client disconnected exception was expected.");
} catch (IgniteClientDisconnectedException e) {
reconnectFut = e.reconnectFuture();
}
assertNotNull(reconnectFut);
startGrid(0);
reconnectFut.get(CLIENT_RECONNECT_WAIT_TIMEOUT);
assertEquals(2, client.cluster().topologyVersion());
assertEquals(0, client.services().serviceDescriptors().size());
client.services().deployNodeSingleton("testService3", MyServiceFactory.create());
final MyService proxy = client.services().serviceProxy("testService3", MyService.class, false, 2_000);
assertNotNull(proxy);
assertEquals(42, proxy.hello());
}
use of org.apache.ignite.internal.processors.service.inner.MyService in project ignite by apache.
the class GridServiceMetricsTest method testServiceMetrics.
/**
* Invokes service in various ways: from clients, servers, etc. Checks these calls reflect in the metrics.
*
* @param serverCnt Number of server nodes.
* @param clientCnt Number of client nodes.
* @param perClusterCnt Number of service instances per cluster.
* @param perNodeCnt Number of service instances per node.
*/
private void testServiceMetrics(int serverCnt, int clientCnt, int perClusterCnt, int perNodeCnt) throws Throwable {
List<IgniteEx> servers = startGrids(serverCnt, false);
List<IgniteEx> clients = startGrids(clientCnt, true);
servers.get(0).services().deploy(serviceCfg(MyServiceFactory.create(), perClusterCnt, perNodeCnt));
awaitPartitionMapExchange();
List<MyService> serverStickyProxies = servers.stream().map(ignite -> (MyService) ignite.services().serviceProxy(SRVC_NAME, MyService.class, true)).collect(Collectors.toList());
List<MyService> clientStickyProxies = clients.stream().map(ignite -> (MyService) ignite.services().serviceProxy(SRVC_NAME, MyService.class, true)).collect(Collectors.toList());
long invokeCollector = 0;
// Call service through the server proxies.
for (int i = 0; i < INVOKE_CNT; ++i) {
// Call from server.
IgniteEx ignite = servers.get(i % servers.size());
callService4Times(ignite, serverStickyProxies.get(i % serverStickyProxies.size()));
// Call from client.
ignite = clients.get(i % clients.size());
callService4Times(ignite, clientStickyProxies.get(i % clientStickyProxies.size()));
invokeCollector += 8;
}
long invokesInMetrics = 0;
// Calculate and check invocations within the metrics.
for (IgniteEx ignite : servers) {
ReadOnlyMetricRegistry metrics = findMetricRegistry(ignite.context().metric(), SRVC_NAME);
// Metrics may not be deployed on this server node.
if (metrics == null)
continue;
for (Metric metric : metrics) {
if (metric instanceof HistogramMetric)
invokesInMetrics += sumHistogramEntries((HistogramMetric) metric);
}
}
// Compare calls number and metrics number.
assertEquals("Calculated wrong service invocation number.", invokesInMetrics, invokeCollector);
}
use of org.apache.ignite.internal.processors.service.inner.MyService in project ignite by apache.
the class GridServiceMetricsTest method callService4Times.
/**
* Executes 2 calls for {@link MyService} though unsticky proxy and 2 calls to {@code extraSrvc}. Total 4 are
* suposed to present in the metrics.
*
* @param ignite Server or client node.
* @param extraSrvc Extra service instance or proxy to call.
*/
private static void callService4Times(IgniteEx ignite, MyService extraSrvc) {
MyService srvc = ignite.services().serviceProxy(SRVC_NAME, MyService.class, false);
srvc.hello();
srvc.hello(1);
extraSrvc.hello();
extraSrvc.hello(2);
}
use of org.apache.ignite.internal.processors.service.inner.MyService in project ignite by apache.
the class GridServicePackagePrivateSelfTest method testPackagePrivateService.
/**
* @throws Exception If failed.
*/
@Test
public void testPackagePrivateService() throws Exception {
try {
Ignite server = startGrid("server");
server.services().deployClusterSingleton("my-service", MyServiceFactory.create());
Ignite client = startClientGrid("client");
MyService svc = client.services().serviceProxy("my-service", MyService.class, true);
assertEquals(42, svc.hello());
} finally {
stopAllGrids();
}
}
Aggregations