Search in sources :

Example 1 with MyService

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);
}
Also used : MyService(org.apache.ignite.internal.processors.service.inner.MyService) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with MyService

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());
}
Also used : MyService(org.apache.ignite.internal.processors.service.inner.MyService) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) LongInitializedTestService(org.apache.ignite.internal.processors.service.inner.LongInitializedTestService) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with MyService

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);
}
Also used : G(org.apache.ignite.internal.util.typedef.G) Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Metric(org.apache.ignite.spi.metric.Metric) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) MyServiceFactory(org.apache.ignite.internal.processors.service.inner.MyServiceFactory) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Service(org.apache.ignite.services.Service) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteServiceProcessor.serviceMetricRegistryName(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.serviceMetricRegistryName) Method(java.lang.reflect.Method) MyService(org.apache.ignite.internal.processors.service.inner.MyService) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) MyService(org.apache.ignite.internal.processors.service.inner.MyService) IgniteEx(org.apache.ignite.internal.IgniteEx) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) Metric(org.apache.ignite.spi.metric.Metric)

Example 4 with MyService

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);
}
Also used : MyService(org.apache.ignite.internal.processors.service.inner.MyService)

Example 5 with MyService

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();
    }
}
Also used : MyService(org.apache.ignite.internal.processors.service.inner.MyService) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

MyService (org.apache.ignite.internal.processors.service.inner.MyService)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 Ignite (org.apache.ignite.Ignite)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 Iterables (com.google.common.collect.Iterables)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 GridMetricManager (org.apache.ignite.internal.processors.metric.GridMetricManager)1 IgniteServiceProcessor.serviceMetricRegistryName (org.apache.ignite.internal.processors.service.IgniteServiceProcessor.serviceMetricRegistryName)1 LongInitializedTestService (org.apache.ignite.internal.processors.service.inner.LongInitializedTestService)1 MyServiceFactory (org.apache.ignite.internal.processors.service.inner.MyServiceFactory)1 G (org.apache.ignite.internal.util.typedef.G)1 IgniteFuture (org.apache.ignite.lang.IgniteFuture)1 Service (org.apache.ignite.services.Service)1