Search in sources :

Example 71 with ClientConfiguration

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

the class ReliableChannelTest method checkFailAfterSendOperation.

/**
 */
private void checkFailAfterSendOperation(Consumer<TcpClientCache> op, boolean channelsReinitOnFail) {
    ClientConfiguration ccfg = new ClientConfiguration().setAddresses(dfltAddrs);
    // Emulate cluster is down after TcpClientChannel#send operation.
    AtomicInteger step = new AtomicInteger();
    ReliableChannel rc = new ReliableChannel((cfg, hnd) -> {
        if (step.getAndIncrement() == 0)
            return new TestAsyncServiceFailureClientChannel();
        else
            return new TestFailureClientChannel();
    }, ccfg, null);
    rc.channelsInit();
    rc.getScheduledChannelsReinit().set(channelsReinitOnFail);
    ClientBinaryMarshaller marsh = mock(ClientBinaryMarshaller.class);
    TcpClientTransactions transactions = mock(TcpClientTransactions.class);
    TcpClientCache cache = new TcpClientCache("", rc, marsh, transactions, null, false, null);
    GridTestUtils.assertThrowsWithCause(() -> op.accept(cache), TestChannelException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 72 with ClientConfiguration

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

the class ReliableChannelTest method testAddressesOrder.

/**
 * Checks that ReliableChannel provides channels in the same order as in ClientConfiguration.
 */
@Test
public void testAddressesOrder() {
    String[] addrs = new String[] { "127.0.0.1:10803", "127.0.0.1:10802", "127.0.0.1:10801", "127.0.0.1:10800" };
    ClientConfiguration ccfg = new ClientConfiguration().setAddresses(addrs);
    ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
    rc.channelsInit();
    List<ReliableChannel.ClientChannelHolder> holders = rc.getChannelHolders();
    assertEquals(addrs.length, holders.size());
    for (int i = 0; i < addrs.length; i++) assertEquals(addrs[i], holders.get(i).getAddress().toString());
}
Also used : ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 73 with ClientConfiguration

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

the class IgniteAwareApplicationService method main.

/**
 * @param args Args.
 */
public static void main(String[] args) throws Exception {
    log.info("Starting Application... [params=" + args[0] + "]");
    String[] params = args[0].split(",");
    IgniteServiceType svcType = IgniteServiceType.valueOf(params[0]);
    Class<?> clazz = Class.forName(params[1]);
    String cfgPath = params[2];
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = params.length > 3 ? mapper.readTree(Base64.getDecoder().decode(params[3])) : mapper.createObjectNode();
    IgniteAwareApplication app = (IgniteAwareApplication) clazz.getConstructor().newInstance();
    app.cfgPath = cfgPath;
    if (svcType == IgniteServiceType.NODE) {
        log.info("Starting Ignite node...");
        IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgs = IgnitionEx.loadConfiguration(cfgPath);
        IgniteConfiguration cfg = cfgs.get1();
        try (Ignite ignite = Ignition.start(cfg)) {
            app.ignite = ignite;
            app.start(jsonNode);
        } finally {
            log.info("Ignite instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
        }
    } else if (svcType == IgniteServiceType.THIN_CLIENT) {
        log.info("Starting thin client...");
        ClientConfiguration cfg = IgnitionEx.loadSpringBean(cfgPath, "thin.client.cfg");
        try (IgniteClient client = Ignition.startClient(cfg)) {
            app.client = client;
            app.start(jsonNode);
        } finally {
            log.info("Thin client instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
        }
    } else if (svcType == IgniteServiceType.NONE)
        app.start(jsonNode);
    else
        throw new IllegalArgumentException("Unknown service type " + svcType);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext) Ignite(org.apache.ignite.Ignite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 74 with ClientConfiguration

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

the class FunctionalQueryTest method testGettingEmptyResultWhenQueryingEmptyTable.

/**
 */
@Test
public void testGettingEmptyResultWhenQueryingEmptyTable() throws Exception {
    try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
        final String TBL = "Person";
        client.query(new SqlFieldsQuery(String.format("CREATE TABLE IF NOT EXISTS " + TBL + " (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", Person.class.getName())).setSchema("PUBLIC")).getAll();
        // IgniteClient#query() API
        List<List<?>> res = client.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll();
        assertNotNull(res);
        assertEquals(0, res.size());
        // ClientCache#query(SqlFieldsQuery) API
        ClientCache<Integer, Person> cache = client.cache("SQL_PUBLIC_" + TBL.toUpperCase());
        res = cache.query(new SqlFieldsQuery("SELECT * FROM " + TBL)).getAll();
        assertNotNull(res);
        assertEquals(0, res.size());
        // ClientCache#query(ScanQuery) and ClientCache#query(SqlQuery) API
        Collection<Query<Cache.Entry<Integer, Person>>> queries = Arrays.asList(new ScanQuery<>(), new SqlQuery<>(Person.class, "1 = 1"));
        for (Query<Cache.Entry<Integer, Person>> qry : queries) {
            try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache.query(qry)) {
                List<Cache.Entry<Integer, Person>> res2 = cur.getAll();
                assertNotNull(res2);
                assertEquals(0, res2.size());
            }
        }
    }
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) SqlQuery(org.apache.ignite.cache.query.SqlQuery) Query(org.apache.ignite.cache.query.Query) ScanQuery(org.apache.ignite.cache.query.ScanQuery) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 75 with ClientConfiguration

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

the class FunctionalQueryTest method testSql.

/**
 * Tested API:
 * <ul>
 * <li>{@link IgniteClient#query(SqlFieldsQuery)}</li>
 * </ul>
 */
@Test
public void testSql() throws Exception {
    try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
        Ignite ignored2 = Ignition.start(Config.getServerConfiguration());
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
        client.query(new SqlFieldsQuery(String.format("CREATE TABLE IF NOT EXISTS Person (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"", Person.class.getName())).setSchema("PUBLIC")).getAll();
        final int KEY_COUNT = 10;
        for (int i = 0; i < KEY_COUNT; ++i) {
            int key = i;
            Person val = new Person(key, "Person " + i);
            client.query(new SqlFieldsQuery("INSERT INTO Person(id, name) VALUES(?, ?)").setArgs(val.getId(), val.getName()).setSchema("PUBLIC")).getAll();
        }
        Object cachedName = client.query(new SqlFieldsQuery("SELECT name from Person WHERE id=?").setArgs(1).setSchema("PUBLIC")).getAll().iterator().next().iterator().next();
        assertEquals("Person 1", cachedName);
        List<List<?>> rows = client.query(new SqlFieldsQuery("SELECT * from Person WHERE id >= ?").setSchema("PUBLIC").setArgs(0).setPageSize(1)).getAll();
        assertEquals(KEY_COUNT, rows.size());
    }
}
Also used : Ignite(org.apache.ignite.Ignite) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) 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