Search in sources :

Example 1 with EVT_SQL_QUERY_EXECUTION

use of org.apache.ignite.events.EventType.EVT_SQL_QUERY_EXECUTION in project ignite by apache.

the class UserQueriesTestBase method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    IgnitePredicate<SqlQueryExecutionEvent> lsnr = evt -> {
        assertNotNull(evt.text());
        SQL_QRY_EXEC_EVT_CNTR.incrementAndGet();
        return true;
    };
    int[] evts = new int[] { EVT_SQL_QUERY_EXECUTION };
    cfg.setIncludeEventTypes(evts);
    cfg.setLocalEventListeners(Collections.singletonMap(lsnr, evts));
    return cfg;
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Metric(org.apache.ignite.spi.metric.Metric) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Collection(java.util.Collection) IgniteEx(org.apache.ignite.internal.IgniteEx) GridRunningQueryInfo(org.apache.ignite.internal.processors.query.GridRunningQueryInfo) SQL_USER_QUERIES_REG_NAME(org.apache.ignite.internal.processors.query.RunningQueryManager.SQL_USER_QUERIES_REG_NAME) Collectors(java.util.stream.Collectors) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TimeUnit(java.util.concurrent.TimeUnit) SqlQueryExecutionEvent(org.apache.ignite.events.SqlQueryExecutionEvent) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Map(java.util.Map) EVT_SQL_QUERY_EXECUTION(org.apache.ignite.events.EventType.EVT_SQL_QUERY_EXECUTION) LongMetric(org.apache.ignite.spi.metric.LongMetric) Assert(org.junit.Assert) Collections(java.util.Collections) SqlQueryExecutionEvent(org.apache.ignite.events.SqlQueryExecutionEvent) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration)

Example 2 with EVT_SQL_QUERY_EXECUTION

use of org.apache.ignite.events.EventType.EVT_SQL_QUERY_EXECUTION 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

Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 EVT_SQL_QUERY_EXECUTION (org.apache.ignite.events.EventType.EVT_SQL_QUERY_EXECUTION)2 SqlQueryExecutionEvent (org.apache.ignite.events.SqlQueryExecutionEvent)2 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)2 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)2 Externalizable (java.io.Externalizable)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1