Search in sources :

Example 81 with ClientConfiguration

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

the class LongDestroyDurableBackgroundTaskTest method batchQuery.

/**
 * Batch query.
 *
 * @param ignite Ignite instance.
 * @param qry SQL query.
 * @param batchArgs Batch arguments.
 * @throws Exception If failed.
 */
private void batchQuery(Ignite ignite, String qry, List<Object[]> batchArgs) throws Exception {
    String host = ignite.configuration().getLocalHost();
    int port = ignite.configuration().getClientConnectorConfiguration().getPort();
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
        try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
            PreparedStatement statement = conn.prepareStatement(qry);
            for (Object[] args : batchArgs) {
                for (int i = 1; i <= args.length; i++) statement.setObject(i, args[i - 1]);
                statement.addBatch();
                statement.clearParameters();
            }
            statement.executeBatch();
        }
    }
}
Also used : IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 82 with ClientConfiguration

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

the class TestClusterClientConnection method testClientConnectsToCluster.

/**
 */
@Test
public void testClientConnectsToCluster() throws Exception {
    mockServerResponse();
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(), false);
    IgniteEx crd = startGrid(cfg);
    String crdAddr = crd.localNode().addresses().iterator().next();
    mockServerResponse(crdAddr);
    ClientConfiguration ccfg = new ClientConfiguration();
    ccfg.setAddressesFinder(new ThinClientKubernetesAddressFinder(prepareConfiguration()));
    IgniteClient client = Ignition.startClient(ccfg);
    ClientCache cache = client.createCache("cache");
    cache.put(1, 2);
    assertEquals(2, cache.get(1));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteEx(org.apache.ignite.internal.IgniteEx) ClientCache(org.apache.ignite.client.ClientCache) ThinClientKubernetesAddressFinder(org.apache.ignite.client.ThinClientKubernetesAddressFinder) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 83 with ClientConfiguration

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

the class ArrayIndexTest method checkTableExpression.

/**
 */
private void checkTableExpression(boolean useTypedArrays) throws Exception {
    System.setProperty(IGNITE_USE_BINARY_ARRAYS, Boolean.toString(useTypedArrays));
    BinaryArray.initUseBinaryArrays();
    try (IgniteEx ex = startGrid(0);
        IgniteEx cli = startClientGrid(1);
        IgniteClient thinCli = Ignition.startClient(new ClientConfiguration().setAddresses(SERVER))) {
        ex.cluster().active(true);
        executeSql(cli, "CREATE TABLE T1 (id int not null, name varchar(1), PRIMARY KEY(id))");
        String insertQry = "INSERT INTO T1(id, name) VALUES (?, ?)";
        executeSql(cli, insertQry, 1, "A");
        executeSql(cli, insertQry, 2, "B");
        executeSql(cli, insertQry, 3, "C");
        String select = "SELECT T1.ID, T1.NAME FROM T1 INNER JOIN TABLE (id2 int = ?) T2 on (T1.id = T2.id2) ORDER BY id";
        Object arg = new Integer[] { 1, 2 };
        Consumer<List<List<?>>> checker = res -> {
            assertNotNull(res);
            assertEquals(2, res.size());
            assertEquals(1, res.get(0).get(0));
            assertEquals("A", res.get(0).get(1));
            assertEquals(2, res.get(1).get(0));
            assertEquals("B", res.get(1).get(1));
        };
        checker.accept(executeSql(ex, select, arg));
        checker.accept(executeSql(cli, select, arg));
        checker.accept(thinCli.query(new SqlFieldsQuery(select).setArgs(arg)).getAll());
    } finally {
        System.clearProperty(IGNITE_USE_BINARY_ARRAYS);
        BinaryArray.initUseBinaryArrays();
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Hex(org.apache.commons.codec.binary.Hex) IgniteCache(org.apache.ignite.IgniteCache) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) BinaryArray(org.apache.ignite.internal.binary.BinaryArray) After(org.junit.After) SERVER(org.apache.ignite.client.Config.SERVER) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IGNITE_USE_BINARY_ARRAYS(org.apache.ignite.IgniteSystemProperties.IGNITE_USE_BINARY_ARRAYS) QueryEntity(org.apache.ignite.cache.QueryEntity) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) Before(org.junit.Before) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

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