Search in sources :

Example 21 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class IgniteBinaryTest method testCompactFooterModifiedSchemaRegistration.

/**
 * Check that binary type schema updates are propagated from client to server and from server to client.
 */
@Test
public void testCompactFooterModifiedSchemaRegistration() throws Exception {
    try (Ignite ignite = Ignition.start(Config.getServerConfiguration())) {
        ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
        ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true));
        try (IgniteClient client1 = Ignition.startClient(cfg);
            IgniteClient client2 = Ignition.startClient(cfg)) {
            ClientCache<Integer, Object> cache1 = client1.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
            ClientCache<Integer, Object> cache2 = client2.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
            String type = "Person";
            // Register type and schema.
            BinaryObjectBuilder builder = client1.binary().builder(type);
            BinaryObject val1 = builder.setField("Name", "Person 1").build();
            cache1.put(1, val1);
            assertEquals("Person 1", ((BinaryObject) cache2.get(1)).field("Name"));
            // Update schema.
            BinaryObject val2 = builder.setField("Name", "Person 2").setField("Age", 2).build();
            cache1.put(2, val2);
            assertEquals("Person 2", ((BinaryObject) cache2.get(2)).field("Name"));
            assertEquals((Integer) 2, ((BinaryObject) cache2.get(2)).field("Age"));
        }
    }
}
Also used : BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class IgniteBinaryTest method testBinaryObjectPutGet.

/**
 * Put/get operations with Ignite Binary Object API
 */
@Test
public void testBinaryObjectPutGet() throws Exception {
    int key = 1;
    try (Ignite ignored = Ignition.start(Config.getServerConfiguration())) {
        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
            IgniteBinary binary = client.binary();
            BinaryObject val = binary.builder("Person").setField("id", 1, int.class).setField("name", "Joe", String.class).build();
            ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
            cache.put(key, val);
            BinaryObject cachedVal = client.cache(Config.DEFAULT_CACHE_NAME).<Integer, BinaryObject>withKeepBinary().get(key);
            assertBinaryObjectsEqual(val, cachedVal);
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) IgniteBinary(org.apache.ignite.IgniteBinary) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class SystemViewSelfTest method testClientsConnections.

/**
 */
@Test
public void testClientsConnections() throws Exception {
    try (IgniteEx g0 = startGrid(0)) {
        String host = g0.configuration().getClientConnectorConfiguration().getHost();
        if (host == null)
            host = g0.configuration().getLocalHost();
        int port = g0.configuration().getClientConnectorConfiguration().getPort();
        SystemView<ClientConnectionView> conns = g0.context().systemView().view(CLI_CONN_VIEW);
        try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
            assertEquals(1, conns.size());
            ClientConnectionView cliConn = conns.iterator().next();
            assertEquals("THIN", cliConn.type());
            assertEquals(cliConn.localAddress().getHostName(), cliConn.remoteAddress().getHostName());
            assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), cliConn.localAddress().getPort());
            assertEquals(cliConn.version(), ProtocolVersion.LATEST_VER.toString());
            try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
                assertEquals(2, conns.size());
                assertEquals(1, F.size(jdbcConnectionsIterator(conns)));
                ClientConnectionView jdbcConn = jdbcConnectionsIterator(conns).next();
                assertEquals("JDBC", jdbcConn.type());
                assertEquals(jdbcConn.localAddress().getHostName(), jdbcConn.remoteAddress().getHostName());
                assertEquals(g0.configuration().getClientConnectorConfiguration().getPort(), jdbcConn.localAddress().getPort());
                assertEquals(jdbcConn.version(), JdbcConnectionContext.CURRENT_VER.asString());
            }
        }
        boolean res = GridTestUtils.waitForCondition(() -> conns.size() == 0, 5_000);
        assertTrue(res);
    }
}
Also used : ClientConnectionView(org.apache.ignite.spi.systemview.view.ClientConnectionView) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteEx(org.apache.ignite.internal.IgniteEx) Connection(java.sql.Connection) Properties(java.util.Properties) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 24 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ComputeTaskRemoteSecurityContextTest method testIgniteClient.

/**
 * Tests task execution security context in case task was initiated from the {@link IgniteClient}.
 */
@Test
public void testIgniteClient() throws Exception {
    String login = "thin_client";
    ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setUserName(login).setUserPassword("");
    try (IgniteClient cli = Ignition.startClient(cfg)) {
        ClientCompute comp = cli.compute(cli.cluster().forNodes(cli.cluster().nodes()));
        if (failWithTimeout)
            comp = comp.withTimeout(TEST_TASK_TIMEOUT);
        String taskName = mapAsync ? MapAsyncTestTask.class.getName() : TestTask.class.getName();
        Throwable timeoutE = null;
        try {
            if (async)
                comp.executeAsync2(taskName, login).get();
            else
                comp.execute(taskName, login);
            checkTaskEvents("crd", login, REDUCER_SUCCEEDED_TASK_EVENTS, MAP_NODE_SUCCEEDED_TASK_EVENTS);
        } catch (Throwable e) {
            if (!failWithTimeout)
                throw e;
            timeoutE = e;
        }
        if (failWithTimeout) {
            assertNotNull(timeoutE);
            assertTrue(X.hasCause(timeoutE, "Task timed out", ClientServerError.class));
            checkTaskEvents("crd", login, REDUCER_FAILED_TASK_EVENTS, MAP_NODE_FAILED_TASK_EVENTS);
        }
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientServerError(org.apache.ignite.internal.client.thin.ClientServerError) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) ClientCompute(org.apache.ignite.client.ClientCompute) Test(org.junit.Test)

Example 25 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class OptimizedMarshallerClassesCachedTest method testLocalDateTimeMetaCached.

/**
 * Test check that meta for classes serialized by {@link OptimizedMarshaller} are cached on client.
 */
@Test
public void testLocalDateTimeMetaCached() throws Exception {
    try (Ignite srv = startGrid(0)) {
        srv.getOrCreateCache(Config.DEFAULT_CACHE_NAME).put(1, LocalDateTime.now());
        IgniteClient cli = new TcpIgniteClient((cfg0, hnd) -> new TcpClientChannel(cfg0, hnd) {

            @Override
            public <T> T service(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) throws ClientException {
                if (op == ClientOperation.GET_BINARY_TYPE_NAME)
                    cnt.incrementAndGet();
                return super.service(op, payloadWriter, payloadReader);
            }

            @Override
            public <T> CompletableFuture<T> serviceAsync(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) {
                if (op == ClientOperation.GET_BINARY_TYPE_NAME)
                    cnt.incrementAndGet();
                return super.serviceAsync(op, payloadWriter, payloadReader);
            }
        }, new ClientConfiguration().setAddresses(Config.SERVER));
        try {
            cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
            cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
        } finally {
            cli.close();
        }
        assertEquals(1, cnt.get());
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IgniteClient(org.apache.ignite.client.IgniteClient) Ignite(org.apache.ignite.Ignite) ClientException(org.apache.ignite.client.ClientException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)83 Test (org.junit.Test)44 IgniteClient (org.apache.ignite.client.IgniteClient)42 Ignite (org.apache.ignite.Ignite)28 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)23 BinaryObject (org.apache.ignite.binary.BinaryObject)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 List (java.util.List)11 Ignition (org.apache.ignite.Ignition)10 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)9 Collections (java.util.Collections)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteBinary (org.apache.ignite.IgniteBinary)7 Connection (java.sql.Connection)6 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Consumer (java.util.function.Consumer)6 ScanQuery (org.apache.ignite.cache.query.ScanQuery)6