/** * */ private static CacheConfiguration createBinCacheConfig() { CacheConfiguration ccfg = cacheConfig("S2P-bin", true, false); QueryEntity e = new QueryEntity(String.class.getName(), "Person"); LinkedHashMap<String, String> flds = new LinkedHashMap<>(); flds.put("id", Integer.class.getName()); flds.put("firstName", String.class.getName()); flds.put("secondName", String.class.getName()); e.setFields(flds); e.setIndexes(Collections.<QueryIndex>emptyList()); ccfg.setQueryEntities(Collections.singletonList(e)); return ccfg; }
/** * */ public static List<QueryEntity> getIndexCfg() { ArrayList<QueryEntity> entities = new ArrayList<>(); QueryEntity qe = new QueryEntity(String.class.getName(), Person.class.getName()); LinkedHashMap<String, String> fieldsMap = new LinkedHashMap<>(); fieldsMap.put("name", String.class.getName()); fieldsMap.put("age", Integer.class.getName()); qe.setFields(fieldsMap); ArrayList<QueryIndex> indices = new ArrayList<>(); QueryIndex index = new QueryIndex("name", true, "LONG_NAME_123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); QueryIndex index2 = new QueryIndex("age", true, "AGE_IDX"); indices.add(index); indices.add(index2); qe.setIndexes(indices); entities.add(qe); return entities; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); CacheConfiguration dfltCacheCfg = defaultCacheConfiguration(); QueryEntity queryEntity = new QueryEntity(Object.class.getName(), Object.class.getName()); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("exceptionOid", Object.class.getName()); queryEntity.setFields(fields); Set<String> keyFields = new HashSet<>(); keyFields.add("exceptionOid"); queryEntity.setKeyFields(keyFields); dfltCacheCfg.setQueryEntities(F.asList(queryEntity)); cfg.setCacheConfiguration(dfltCacheCfg); return cfg; }
/** * @param idx Node index. * @return Client configuration. * @throws Exception if failed. */ protected IgniteConfiguration clientConfiguration(int idx) throws Exception { QueryEntity e = new QueryEntity(Integer.class.getName(), "Person"); LinkedHashMap<String, String> flds = new LinkedHashMap<>(); flds.put("name", String.class.getName()); e.setFields(flds); return commonConfiguration(idx).setClientMode(true).setCacheConfiguration( new CacheConfiguration<>("idx").setQueryEntities(Collections.singletonList(e)) ); }
/** * @return cache configuration with test table */ @NotNull private CacheConfiguration<Object, Object> getTestTableConfiguration() { LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("a", "java.lang.Integer"); fields.put("B", "java.lang.String"); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); ccfg.setQueryEntities(Collections.singletonList( new QueryEntity() .setKeyType("java.lang.Integer") .setValueType("TestIndexObject") .setFields(fields) )); return ccfg; } }
/** */ private CacheConfiguration cacheACfg() { CacheConfiguration<?,?> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); cfg.setName("A"); QueryEntity eA = new QueryEntity(Integer.class.getName(), "A"); eA.setFields(fieldsAA); QueryEntity eB = new QueryEntity(Integer.class.getName(), "B"); eB.setFields(fieldsAB); List<QueryEntity> list = new ArrayList<>(2); list.add(eA); list.add(eB); QueryIndex idx = new QueryIndex("txt"); idx.setIndexType(QueryIndexType.FULLTEXT); eB.setIndexes(Collections.singleton(idx)); cfg.setQueryEntities(list); return cfg; }
/** * @param parentCfg Parent config. * @return Configuration. */ private static CacheConfiguration<Object, Object> getDepositCfg(CacheConfiguration<Object, Object> parentCfg) { CacheConfiguration<Object, Object> depositCfg = new CacheConfiguration<>(parentCfg); depositCfg.setName(DEPOSIT_CACHE); String strCls = String.class.getCanonicalName(); String dblCls = Double.class.getCanonicalName(); String intCls = Integer.class.getCanonicalName(); LinkedHashMap<String, String> qryFields = new LinkedHashMap<>(); qryFields.put(ID, strCls); qryFields.put(TRADER_ID, strCls); qryFields.put(TRADER_LINK, intCls); qryFields.put(BALANCE, dblCls); qryFields.put(MARGIN_RATE, dblCls); qryFields.put(BALANCE_ON_DAY_OPEN, dblCls); QueryEntity qryEntity = new QueryEntity(); qryEntity.setValueType(DEPOSIT); qryEntity.setKeyType(strCls); qryEntity.setFields(qryFields); qryEntity.setIndexes(Collections.singleton(new QueryIndex(ID, false))); depositCfg.setQueryEntities(Collections.singleton(qryEntity)); return depositCfg; }
/** * @param parentCfg Parent config. * @return Configuration. */ private static CacheConfiguration<Object, Object> getDepositHistoryCfg( CacheConfiguration<Object, Object> parentCfg) { CacheConfiguration<Object, Object> depositHistCfg = new CacheConfiguration<>(parentCfg); depositHistCfg.setName(DEPOSIT_HISTORY_CACHE); String strCls = String.class.getCanonicalName(); String dblCls = Double.class.getCanonicalName(); String dtCls = Date.class.getCanonicalName(); LinkedHashMap<String, String> qryFields = new LinkedHashMap<>(); qryFields.put(ID, strCls); qryFields.put(DEPOSIT_ID, strCls); qryFields.put(BUSINESS_DAY, dtCls); qryFields.put(BALANCE, dblCls); QueryEntity qryEntity = new QueryEntity(); qryEntity.setValueType(OPERATION); qryEntity.setKeyType(strCls); qryEntity.setFields(qryFields); qryEntity.setIndexes(Arrays.asList(new QueryIndex(ID, true), new QueryIndex(DEPOSIT_ID, true))); depositHistCfg.setQueryEntities(Collections.singleton(qryEntity)); return depositHistCfg; }
/** * @param cacheName Cache name. * @return Cache configuration. */ private CacheConfiguration<Integer, IndexedType> cacheConfiguration(String cacheName) { CacheConfiguration<Integer, IndexedType> ccfg = new CacheConfiguration<>(cacheName); QueryEntity entity = new QueryEntity(Integer.class.getName(), IndexedType.class.getName()); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); // Test will pass if we use java.lang.Integer instead of int. fields.put("iVal", "int"); entity.setFields(fields); entity.setIndexes(F.asList( new QueryIndex("iVal") )); ccfg.setQueryEntities(F.asList(entity)); return ccfg; }
@Override public Object call() throws Exception { QueryEntity e = new QueryEntity(); e.setTableName("City"); e.setKeyFields(Collections.singleton("name")); e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName()))); e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx"))); e.setKeyType("CityKey"); e.setValueType("City"); queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null, null, CacheAtomicityMode.ATOMIC, null, 10, false, false); return null; } }, SchemaOperationException.class, "Index already exists: idx");
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setMarshaller(null); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(TestBuilderValue.class.getName()); ArrayList<QueryIndex> idxs = new ArrayList<>(); QueryIndex idx = new QueryIndex("iVal"); idxs.add(idx); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("iVal", Integer.class.getName()); entity.setFields(fields); entity.setIndexes(idxs); ccfg.setQueryEntities(Collections.singleton(entity)); cfg.setCacheConfiguration(ccfg); BinaryConfiguration binaryCfg = new BinaryConfiguration(); BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(); typeCfg.setTypeName(TestBuilderValue.class.getName()); binaryCfg.setTypeConfigurations(Collections.singletonList(typeCfg)); cfg.setBinaryConfiguration(binaryCfg); return cfg; }
/** * @throws Exception If failed. */ @Test public void testClassDuplicatesQueryEntity() throws Exception { String cacheName = "duplicate"; CacheConfiguration ccfg = new CacheConfiguration(cacheName); ccfg.setIndexedTypes(Integer.class, Person.class); QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Person.class.getName()); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("name", String.class.getName()); entity.setFields(fields); ccfg.setQueryEntities(Arrays.asList(entity)); try { ignite(0).getOrCreateCache(ccfg); } finally { ignite(0).destroyCache(cacheName); } }
/** * @throws Exception If failed. */ @Test public void testClassDuplicatesQueryReverse() throws Exception { String cacheName = "duplicate"; CacheConfiguration ccfg = new CacheConfiguration(cacheName); QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Person.class.getName()); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("name", String.class.getName()); entity.setFields(fields); ccfg.setQueryEntities(Arrays.asList(entity)); ccfg.setIndexedTypes(Integer.class, Person.class); try { ignite(0).getOrCreateCache(ccfg); } finally { ignite(0).destroyCache(cacheName); } }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); CacheConfiguration cache = new CacheConfiguration(DEFAULT_CACHE_NAME); cache.setCacheMode(PARTITIONED); cache.setAtomicityMode(atomicityMode()); cache.setWriteSynchronizationMode(FULL_SYNC); cache.setBackups(1); cache.setRebalanceMode(CacheRebalanceMode.SYNC); QueryEntity qryEntity = new QueryEntity(); qryEntity.setKeyType(AffinityKey.class.getName()); qryEntity.setValueType(IndexedEntity.class.getName()); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("val", String.class.getName()); qryEntity.setFields(fields); qryEntity.setIndexes(Arrays.asList(new QueryIndex("val", QueryIndexType.FULLTEXT))); cache.setQueryEntities(Arrays.asList(qryEntity)); cfg.setCacheConfiguration(cache); TcpCommunicationSpi commSpi = new TcpCommunicationSpi(); commSpi.setSharedMemoryPort(-1); cfg.setCommunicationSpi(commSpi); return cfg; }
/** * @throws Exception In case of an error. */ @Test public void testEntryReadQueryEntities() throws Exception { Ignite ignite = startGrid(0); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache binary = ignite.createCache(new CacheConfiguration<>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');")); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');")); GridTestUtils.assertThrowsAnyCause( log, new Callable<Object>() { @Override public Object call() { return ignite.cache("binary").iterator().next(); } }, BinaryInvalidTypeException.class, "IdKey"); }
/** * @throws Exception In case of an error. */ @Test public void testValueReadQueryEntities() throws Exception { Ignite ignite = startGrid(0); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache binary = ignite.createCache(new CacheConfiguration<>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary")))); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');")); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');")); GridTestUtils.assertThrowsAnyCause( log, new Callable<Object>() { @Override public Object call() { return ignite.cache("binary").get(1); } }, BinaryInvalidTypeException.class, "Payload"); }
/** * @throws Exception In case of an error. */ @Test public void testValueWriteMultipleQueryEntities() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<Integer, Payload> binary = ignite.createCache(new CacheConfiguration<Integer, Payload>() .setName("binary").setQueryEntities(Arrays.asList( new QueryEntity().setKeyType("Foo").setKeyFieldName("id") .setValueType("Bar").setFields(fields).setTableName("regular"), new QueryEntity().setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(1, new Payload("foo")); binary.put(2, new Payload("bar")); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), "valType=o.a.i.i.processors.cache.BinaryTypeMismatchLoggingTest$Payload"); }
/** * @throws Exception In case of an error. */ @Test public void testEntryWriteCacheIsolation() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<IdKey, Payload> regular = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("regular").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType(getClass().getName() + "$IdKey").setKeyFields(Collections.singleton("id")) .setValueType(getClass().getName() + "$Payload").setFields(fields).setTableName("binary")))); IgniteCache<IdKey, Payload> binary = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); regular.put(new IdKey(1), new Payload("foo")); regular.put(new IdKey(2), new Payload("bar")); binary.put(new IdKey(1), new Payload("foo")); binary.put(new IdKey(2), new Payload("bar")); assertEquals(0, countRows(binary)); assertEquals(2, countRows(regular)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); }
/** * @throws Exception In case of an error. */ @Test public void testValueWriteQueryEntities() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<Integer, Object> binary = ignite.createCache(new CacheConfiguration<Integer, Object>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(1, new Payload("foo")); binary.put(2, new IdKey(2)); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); assertContainsExactlyOnce(capture.toString(), "expValType=Payload, actualValType=o.a.i.i.processors.cache.BinaryTypeMismatchLoggingTest$IdKey"); }
/** * @throws Exception In case of an error. */ @Test public void testEntryWriteQueryEntities() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<IdKey, Payload> binary = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(new IdKey(1), new Payload("foo")); binary.put(new IdKey(2), new Payload("bar")); assertEquals(0, countRows(binary)); binary.destroy(); binary = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(new IdKey(1), new Payload("foo")); binary.put(new IdKey(2), new Payload("bar")); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); }