/** * @throws Exception If failed. */ @Test public void testSimpleIndexingSpi() throws Exception { indexingSpi = new MyIndexingSpi(); Ignite ignite = startGrid(0); CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(DEFAULT_CACHE_NAME); IgniteCache<Integer, Integer> cache = ignite.createCache(ccfg); for (int i = 0; i < 10; i++) cache.put(i, i); QueryCursor<Cache.Entry<Integer, Integer>> cursor = cache.query(new SpiQuery<Integer, Integer>().setArgs(2, 5)); for (Cache.Entry<Integer, Integer> entry : cursor) System.out.println(entry); }
/** * Convert query arguments to BinaryObjects if binary marshaller used. * * @param qry Query. */ private void convertToBinary(final Query qry) { GridCacheContext<K, V> ctx = getContextSafe(); if (ctx.binaryMarshaller()) { if (qry instanceof SqlQuery) { final SqlQuery sqlQry = (SqlQuery) qry; convertToBinary(sqlQry.getArgs()); } else if (qry instanceof SpiQuery) { final SpiQuery spiQry = (SpiQuery) qry; convertToBinary(spiQry.getArgs()); } else if (qry instanceof SqlFieldsQuery) { final SqlFieldsQuery fieldsQry = (SqlFieldsQuery) qry; convertToBinary(fieldsQry.getArgs()); } } }
/** * Tests that SPI queries are executed in dedicated pool * @throws Exception If failed. */ @Test public void testSpiQueryUsesDedicatedThreadPool() throws Exception { try (Ignite client = startGrid("client")) { IgniteCache<Byte, Byte> cache = client.cache(CACHE_NAME); for (byte b = 0; b < Byte.MAX_VALUE; ++b) cache.put(b, b); QueryCursor<Cache.Entry<Byte, Byte>> cursor = cache.query(new SpiQuery<Byte, Byte>()); List<Cache.Entry<Byte, Byte>> all = cursor.getAll(); assertEquals(1, all.size()); assertEquals(GridIoPolicy.QUERY_POOL, (byte)all.get(0).getValue()); cursor.close(); } }
/** * @throws Exception If failed. */ @Test public void testIndexingSpiWithDisabledQueryProcessor() throws Exception { indexingSpi = new MyIndexingSpi(); Ignite ignite = startGrid(0); CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(DEFAULT_CACHE_NAME); IgniteCache<Integer, Integer> cache = ignite.createCache(ccfg); for (int i = 0; i < 10; i++) cache.put(i, i); QueryCursor<Cache.Entry<Integer, Integer>> cursor = cache.query(new SpiQuery<Integer, Integer>().setArgs(2, 5)); for (Cache.Entry<Integer, Integer> entry : cursor) System.out.println(entry); }
/** * Convert query arguments to BinaryObjects if binary marshaller used. * * @param qry Query. */ private void convertToBinary(final Query qry) { if (ctx.binaryMarshaller()) { if (qry instanceof SqlQuery) { final SqlQuery sqlQry = (SqlQuery) qry; convertToBinary(sqlQry.getArgs()); } else if (qry instanceof SpiQuery) { final SpiQuery spiQry = (SpiQuery) qry; convertToBinary(spiQry.getArgs()); } else if (qry instanceof SqlFieldsQuery) { final SqlFieldsQuery fieldsQry = (SqlFieldsQuery) qry; convertToBinary(fieldsQry.getArgs()); } } }
/** * @throws Exception If failed. */ @Test public void testNonBinaryIndexingSpi() throws Exception { System.setProperty(IgniteSystemProperties.IGNITE_UNWRAP_BINARY_FOR_INDEXING_SPI, "true"); try { indexingSpi = new MyIndexingSpi(); Ignite ignite = startGrid(0); CacheConfiguration<PersonKey, Person> ccfg = cacheConfiguration(DEFAULT_CACHE_NAME); IgniteCache<PersonKey, Person> cache = ignite.createCache(ccfg); for (int i = 0; i < 10; i++) { PersonKey key = new PersonKey(i); cache.put(key, new Person("John Doe " + i)); } QueryCursor<Cache.Entry<PersonKey, Person>> cursor = cache.query( new SpiQuery<PersonKey, Person>().setArgs(new PersonKey(2), new PersonKey(5))); for (Cache.Entry<PersonKey, Person> entry : cursor) System.out.println(entry); cache.remove(new PersonKey(9)); } finally { System.clearProperty(IgniteSystemProperties.IGNITE_UNWRAP_BINARY_FOR_INDEXING_SPI); } }
/** * @throws Exception If failed. */ @Test public void testBinaryIndexingSpi() throws Exception { indexingSpi = new MyBinaryIndexingSpi(); Ignite ignite = startGrid(0); CacheConfiguration<PersonKey, Person> ccfg = cacheConfiguration(DEFAULT_CACHE_NAME); IgniteCache<PersonKey, Person> cache = ignite.createCache(ccfg); for (int i = 0; i < 10; i++) { PersonKey key = new PersonKey(i); cache.put(key, new Person("John Doe " + i)); } QueryCursor<Cache.Entry<PersonKey, Person>> cursor = cache.query( new SpiQuery<PersonKey, Person>().setArgs(new PersonKey(2), new PersonKey(5))); for (Cache.Entry<PersonKey, Person> entry : cursor) System.out.println(entry); cache.remove(new PersonKey(9)); }