/** * @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); }
/** * @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); }
/** * @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)); }