Search in sources :

Example 1 with ValueType

use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.

the class QueryAdvancedTest method testMapWithIndexAfterShutDown.

@Test
public void testMapWithIndexAfterShutDown() {
    Config config = getConfig();
    String mapName = "default";
    config.getMapConfig(mapName).addIndexConfig(new IndexConfig(IndexType.HASH, "typeName"));
    HazelcastInstance[] instances = createHazelcastInstanceFactory(3).newInstances(config);
    final IMap<Integer, ValueType> map = instances[0].getMap(mapName);
    final int sampleSize1 = 100;
    final int sampleSize2 = 30;
    int totalSize = sampleSize1 + sampleSize2;
    for (int i = 0; i < sampleSize1; i++) {
        map.put(i, new ValueType("type" + i));
    }
    for (int i = sampleSize1; i < totalSize; i++) {
        map.put(i, new ValueType("typex"));
    }
    Collection typexValues = map.values(Predicates.sql("typeName = typex"));
    assertEquals(sampleSize2, typexValues.size());
    instances[1].shutdown();
    assertEquals(totalSize, map.size());
    assertTrueEventually(() -> {
        final Collection values = map.values(Predicates.sql("typeName = typex"));
        assertEquals(sampleSize2, values.size());
    });
    instances[2].shutdown();
    assertEquals(totalSize, map.size());
    assertTrueEventually(() -> {
        final Collection values = map.values(Predicates.sql("typeName = typex"));
        assertEquals(sampleSize2, values.size());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ValueType

use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.

the class QueryBasicTest method testInPredicateWithEmptyArray.

@Test(timeout = 1000 * 90)
public void testInPredicateWithEmptyArray() {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    cfg.setProperty(QueryEngineImpl.DISABLE_MIGRATION_FALLBACK.getName(), "true");
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
    final IMap<String, Value> map = instance.getMap("default");
    for (int i = 0; i < 10; i++) {
        final Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    String[] emptyArray = new String[2];
    final Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("name").in(emptyArray);
    final Collection<Value> values = map.values(predicate);
    assertEquals(values.size(), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) Value(com.hazelcast.query.SampleTestObjects.Value) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ValueType

use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.

the class QueryBasicTest method issue393SqlInInteger.

@Test(timeout = 1000 * 90)
public void issue393SqlInInteger() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Value> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "index");
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = Predicates.sql("index IN (0, 2)");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0", "name2" };
    assertEquals(expectedValues.length, values.size());
    List<String> names = new ArrayList<>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[0]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) ArrayList(java.util.ArrayList) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ValueType

use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.

the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.

/**
 * see pull request 616
 */
@Test(timeout = 1000 * 90)
public void testIndexingEnumAttributeWithSqlIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex(IndexType.SORTED, "state");
    for (int i = 0; i < 4; i++) {
        Value v = new Value(i % 2 == 0 ? State.STATE1 : State.STATE2, new ValueType(), i);
        map.put(i, v);
    }
    Collection<Value> values = map.values(Predicates.sql("state = 'STATE1'"));
    int[] expectedValues = new int[] { 0, 2 };
    assertEquals(expectedValues.length, values.size());
    int[] indexes = new int[2];
    int index = 0;
    for (Value configObject : values) {
        indexes[index++] = configObject.getIndex();
    }
    Arrays.sort(indexes);
    assertArrayEquals(indexes, expectedValues);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ValueType

use of com.hazelcast.query.SampleTestObjects.ValueType in project hazelcast by hazelcast.

the class QueryIndexTest method testInnerIndex.

@Test(timeout = 1000 * 60)
public void testInnerIndex() {
    HazelcastInstance instance = createTestHazelcastInstance();
    IMap<String, SampleTestObjects.Value> map = instance.getMap("default");
    map.addIndex(IndexType.HASH, "name");
    map.addIndex(IndexType.HASH, "type.typeName");
    for (int i = 0; i < 10; i++) {
        Value v = new Value("name" + i, i < 5 ? null : new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = Predicates.newPredicateBuilder().getEntryObject().get("type.typeName").in("type8", "type6");
    Collection<SampleTestObjects.Value> values = map.values(predicate);
    assertEquals(2, values.size());
    List<String> typeNames = new ArrayList<>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    String[] array = typeNames.toArray(new String[0]);
    Arrays.sort(array);
    assertArrayEquals(typeNames.toString(), new String[] { "type6", "type8" }, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleTestObjects.ValueType) Value(com.hazelcast.query.SampleTestObjects.Value) ArrayList(java.util.ArrayList) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 ValueType (com.hazelcast.query.SampleTestObjects.ValueType)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 Predicate (com.hazelcast.query.Predicate)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 Value (com.hazelcast.query.SampleTestObjects.Value)6 ArrayList (java.util.ArrayList)3 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 Collection (java.util.Collection)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1