Search in sources :

Example 76 with ClientConfiguration

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

the class FunctionalQueryTest method testMixedQueryAndCacheApiOperations.

/**
 */
@Test
public void testMixedQueryAndCacheApiOperations() throws Exception {
    try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)).setAddresses(Config.SERVER))) {
        String cacheName = "PersonCache";
        client.query(new SqlFieldsQuery(String.format("CREATE TABLE IF NOT EXISTS Person (key INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s,CACHE_NAME=%s\"", Person.class.getName(), cacheName)).setSchema("PUBLIC")).getAll();
        client.query(new SqlFieldsQuery("INSERT INTO Person(key, name) VALUES(?, ?)").setArgs(1, "Person 1").setSchema("PUBLIC")).getAll();
        ClientCache<Integer, Person> cache = client.cache(cacheName);
        cache.put(2, new Person(2, "Person 2"));
        assertEquals("Person 1", cache.get(1).getName());
        assertEquals("Person 2", client.query(new SqlFieldsQuery("SELECT name FROM PUBLIC.Person WHERE key = 2")).getAll().get(0).get(0));
    }
}
Also used : BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) Ignite(org.apache.ignite.Ignite) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 77 with ClientConfiguration

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

the class SecurityTest method testInvalidUserAuthentication.

/**
 * Test valid user authentication.
 */
private void testInvalidUserAuthentication(Consumer<IgniteClient> action) {
    Exception authError = null;
    try (Ignite ignored = igniteWithAuthentication();
        IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setUserName("JOE").setUserPassword("password"))) {
        action.accept(client);
    } catch (Exception e) {
        authError = e;
    }
    assertNotNull("Authentication with invalid credentials succeeded", authError);
    assertTrue("Invalid type of authentication error", authError instanceof ClientAuthenticationException);
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteClientException(org.apache.ignite.internal.processors.platform.client.IgniteClientException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ExecutionException(java.util.concurrent.ExecutionException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 78 with ClientConfiguration

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

the class SqlViewExporterSpiTest method testClientsConnections.

/**
 */
@Test
public void testClientsConnections() throws Exception {
    String host = ignite0.configuration().getClientConnectorConfiguration().getHost();
    if (host == null)
        host = ignite0.configuration().getLocalHost();
    int port = ignite0.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())) {
            List<List<?>> conns = execute(ignite0, "SELECT * FROM SYS.CLIENT_CONNECTIONS");
            assertEquals(2, conns.size());
        }
    }
}
Also used : IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) Connection(java.sql.Connection) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) AbstractExporterSpiTest(org.apache.ignite.internal.metric.AbstractExporterSpiTest) Test(org.junit.Test)

Example 79 with ClientConfiguration

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

the class WrongQueryEntityFieldTypeTest method withThinClient.

/**
 * Perform action with Thin client.
 */
private void withThinClient(BiConsumer<IgniteClient, ClientCache<Integer, Object>> consumer) throws Exception {
    startGrids(gridCnt);
    try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1:10800"))) {
        ClientCache<Integer, Object> cache = cli.createCache(new ClientCacheConfiguration().setName("TEST").setAtomicityMode(mode).setBackups(backups).setQueryEntities(queryEntity()));
        consumer.accept(cli, cache);
        assertFalse(sysThreadFail);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration)

Example 80 with ClientConfiguration

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

the class IgniteCacheAbstractQuerySelfTest method doTestClientQueryExecutedEvents.

/**
 */
public void doTestClientQueryExecutedEvents(boolean inclSens) throws Exception {
    CountDownLatch execLatch = new CountDownLatch(9);
    IgnitePredicate<SqlQueryExecutionEvent> lsnr = evt -> {
        assertNotNull(evt.text());
        if (inclSens)
            assertTrue(evt.toString().contains("args="));
        else
            assertFalse(evt.toString().contains("args="));
        execLatch.countDown();
        return true;
    };
    ignite().events().localListen(lsnr, EVT_SQL_QUERY_EXECUTION);
    ClientConfiguration cc = new ClientConfiguration().setAddresses(Config.SERVER);
    try (IgniteClient client = Ignition.startClient(cc)) {
        client.query(new SqlFieldsQuery("create table TEST_TABLE(key int primary key, val int)")).getAll();
        client.query(new SqlFieldsQuery("insert into TEST_TABLE values (?, ?)").setArgs(1, 1)).getAll();
        client.query(new SqlFieldsQuery("update TEST_TABLE set val = ?2 where key = ?1").setArgs(1, 2)).getAll();
        client.query(new SqlFieldsQuery("select * from TEST_TABLE")).getAll();
        client.query(new SqlFieldsQuery("create index idx_1 on TEST_TABLE(key)")).getAll();
        client.query(new SqlFieldsQuery("drop index idx_1")).getAll();
        client.query(new SqlFieldsQuery("alter table TEST_TABLE add column val2 int")).getAll();
        client.query(new SqlFieldsQuery("alter table TEST_TABLE drop val2")).getAll();
        client.query(new SqlFieldsQuery("drop table TEST_TABLE")).getAll();
        assert execLatch.await(3_000, MILLISECONDS);
    } finally {
        ignite().events().stopLocalListen(lsnr, EVT_SQL_QUERY_EXECUTION);
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) ObjectOutput(java.io.ObjectOutput) SYNC(org.apache.ignite.cache.CacheRebalanceMode.SYNC) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) SCAN(org.apache.ignite.internal.processors.cache.query.CacheQueryType.SCAN) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Map(java.util.Map) SqlQuery(org.apache.ignite.cache.query.SqlQuery) Cache(javax.cache.Cache) IgniteBinary(org.apache.ignite.IgniteBinary) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheStore(org.apache.ignite.cache.store.CacheStore) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) CachePeekMode(org.apache.ignite.cache.CachePeekMode) QuerySqlField(org.apache.ignite.cache.query.annotations.QuerySqlField) Externalizable(java.io.Externalizable) EventType(org.apache.ignite.events.EventType) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) CacheStoreAdapter(org.apache.ignite.cache.store.CacheStoreAdapter) QueryCursorEx(org.apache.ignite.internal.processors.cache.query.QueryCursorEx) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) ObjectInput(java.io.ObjectInput) FULL_TEXT(org.apache.ignite.internal.processors.cache.query.CacheQueryType.FULL_TEXT) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) QuerySqlFunction(org.apache.ignite.cache.query.annotations.QuerySqlFunction) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SqlQueryExecutionEvent(org.apache.ignite.events.SqlQueryExecutionEvent) Config(org.apache.ignite.client.Config) IgniteClient(org.apache.ignite.client.IgniteClient) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) S(org.apache.ignite.internal.util.typedef.internal.S) EVT_CACHE_QUERY_OBJECT_READ(org.apache.ignite.events.EventType.EVT_CACHE_QUERY_OBJECT_READ) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CacheException(javax.cache.CacheException) EVT_SQL_QUERY_EXECUTION(org.apache.ignite.events.EventType.EVT_SQL_QUERY_EXECUTION) Duration(javax.cache.expiry.Duration) Factory(javax.cache.configuration.Factory) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) Iterator(java.util.Iterator) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) QueryTextField(org.apache.ignite.cache.query.annotations.QueryTextField) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) TextQuery(org.apache.ignite.cache.query.TextQuery) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Comparator(java.util.Comparator) GridToStringBuilder(org.apache.ignite.internal.util.tostring.GridToStringBuilder) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) EVT_CACHE_QUERY_EXECUTED(org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED) CacheMode(org.apache.ignite.cache.CacheMode) SqlQueryExecutionEvent(org.apache.ignite.events.SqlQueryExecutionEvent) IgniteClient(org.apache.ignite.client.IgniteClient) CountDownLatch(java.util.concurrent.CountDownLatch) 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