use of org.apache.ignite.cache.CacheMode in project ignite by apache.
the class JettyRestProcessorAbstractSelfTest method testTypedGet.
/**
* @throws Exception If failed.
*/
@Test
public void testTypedGet() throws Exception {
// Test boolean type.
IgniteCache<Boolean, Boolean> cBool = typedCache();
cBool.put(true, false);
cBool.put(false, true);
getTypedValue("boolean", "true", "false");
getTypedValue("java.lang.Boolean", "false", "true");
// Test byte type.
IgniteCache<Byte, Byte> cByte = typedCache();
cByte.put((byte) 77, (byte) 55);
cByte.put((byte) -88, (byte) -10);
getTypedValue("byte", "77", "55");
getTypedValue("java.lang.Byte", "-88", "-10");
// Test short type.
IgniteCache<Short, Short> cShort = typedCache();
cShort.put((short) 2222, (short) 3333);
cShort.put((short) -11111, (short) -12222);
getTypedValue("short", "2222", "3333");
getTypedValue("java.lang.Short", "-11111", "-12222");
// Test integer type.
IgniteCache<Integer, Integer> cInt = typedCache();
cInt.put(65555, 128256);
cInt.put(74555, 200000);
cInt.put(-200, -100000);
getTypedValue("int", "65555", "128256");
getTypedValue("Integer", "74555", "200000");
getTypedValue("java.lang.Integer", "-200", "-100000");
// Test long type.
IgniteCache<Long, Long> cLong = typedCache();
cLong.put(3333333L, 4444444L);
cLong.put(-3333333L, -4444444L);
getTypedValue("long", "3333333", "4444444");
getTypedValue("java.lang.Long", "-3333333", "-4444444");
// Test float type.
IgniteCache<Float, Float> cFloat = typedCache();
cFloat.put(11.5f, 21.5f);
cFloat.put(-71.5f, -81.5f);
getTypedValue("float", "11.5", "21.5");
getTypedValue("java.lang.Float", "-71.5", "-81.5");
// Test double type.
IgniteCache<Double, Double> cDouble = typedCache();
cDouble.put(58.5d, 758.5d);
cDouble.put(-1558.5d, -2558.5d);
getTypedValue("double", "58.5", "758.5");
getTypedValue("java.lang.Double", "-1558.5", "-2558.5");
// Test date type.
IgniteCache<Date, Date> cDate = typedCache();
cDate.put(Date.valueOf("2018-02-18"), Date.valueOf("2017-01-01"));
cDate.put(Date.valueOf("2018-01-01"), Date.valueOf("2017-02-02"));
getTypedValue("Date", "2018-02-18", "2017-01-01");
getTypedValue("java.sql.Date", "2018-01-01", "2017-02-02");
// Test time type.
IgniteCache<Time, Time> cTime = typedCache();
cTime.put(Time.valueOf("01:01:01"), Time.valueOf("02:02:02"));
cTime.put(Time.valueOf("03:03:03"), Time.valueOf("04:04:04"));
getTypedValue("Time", "01:01:01", "02:02:02");
getTypedValue("java.sql.Time", "03:03:03", "04:04:04");
// Test timestamp type.
IgniteCache<Timestamp, String> cTimestamp = typedCache();
cTimestamp.put(Timestamp.valueOf("2018-02-18 01:01:01"), "test1");
cTimestamp.put(Timestamp.valueOf("2018-01-01 01:01:01"), "test2");
getTypedValue("Timestamp", "2018-02-18 01:01:01", "test1");
getTypedValue("java.sql.timestamp", "2018-01-01 01:01:01", "test2");
// Test UUID type.
IgniteCache<UUID, UUID> cUUID = typedCache();
UUID k1 = UUID.fromString("121f5ae8-148d-11e8-b642-0ed5f89f718b");
UUID v1 = UUID.fromString("64c6c225-b31c-4000-b136-ef14562ac785");
cUUID.put(k1, v1);
UUID k2 = UUID.randomUUID();
UUID v2 = UUID.randomUUID();
cUUID.put(k2, v2);
getTypedValue("UUID", k1.toString(), v1.toString());
getTypedValue("java.util.UUID", k2.toString(), v2.toString());
// Test IgniteUuid type.
IgniteCache<IgniteUuid, IgniteUuid> cIgniteUUID = typedCache();
IgniteUuid ik1 = IgniteUuid.randomUuid();
IgniteUuid iv1 = IgniteUuid.randomUuid();
cIgniteUUID.put(ik1, iv1);
IgniteUuid ik2 = IgniteUuid.randomUuid();
IgniteUuid iv2 = IgniteUuid.randomUuid();
cIgniteUUID.put(ik2, iv2);
getTypedValue("IgniteUuid", ik1.toString(), iv1.toString());
getTypedValue("org.apache.ignite.lang.IgniteUuid", ik2.toString(), iv2.toString());
// Test tuple.
IgniteCache<Integer, T2<Integer, String>> cTuple = typedCache();
T2<Integer, String> tup = new T2<>(1, "test");
cTuple.put(555, tup);
getTypedValue("int", "555", JSON_MAPPER.writeValueAsString(tup));
// Test enum.
IgniteCache<Integer, CacheMode> cEnum = typedCache();
cEnum.put(888, PARTITIONED);
getTypedValue("int", "888", PARTITIONED.toString());
}
use of org.apache.ignite.cache.CacheMode in project ignite by apache.
the class ScanQueriesTopologyMappingTest method checkQueryWithNodeFilter.
/**
*/
private void checkQueryWithNodeFilter(CacheMode cacheMode) throws Exception {
IgniteEx ign0 = startGrid(0);
String name0 = ign0.name();
IgniteCache<Object, Object> cache0 = ign0.createCache(new CacheConfiguration<>(GridAbstractTest.DEFAULT_CACHE_NAME).setCacheMode(cacheMode).setNodeFilter(node -> name0.equals(node.attribute(ATTR_IGNITE_INSTANCE_NAME))));
cache0.put(1, 2);
startGrid(1);
client = true;
startGrid(10);
int part = ign0.affinity(DEFAULT_CACHE_NAME).partition(1);
for (int i = 0; i < 100; i++) {
for (Ignite ign : G.allGrids()) {
IgniteCache<Object, Object> cache = ign.cache(GridAbstractTest.DEFAULT_CACHE_NAME);
List<Cache.Entry<Object, Object>> res = cache.query(new ScanQuery<>()).getAll();
assertEquals(1, res.size());
assertEquals(1, res.get(0).getKey());
assertEquals(2, res.get(0).getValue());
res = new ArrayList<>();
for (Cache.Entry<Object, Object> entry : cache) {
res.add(entry);
}
assertEquals(1, res.size());
assertEquals(1, res.get(0).getKey());
assertEquals(2, res.get(0).getValue());
res = cache.query(new ScanQuery<>(part)).getAll();
assertEquals(1, res.size());
assertEquals(1, res.get(0).getKey());
assertEquals(2, res.get(0).getValue());
}
ScanQuery<Object, Object> qry = new ScanQuery<>().setLocal(true);
{
List<Cache.Entry<Object, Object>> res0 = grid(0).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
assertEquals(1, res0.size());
assertEquals(1, res0.get(0).getKey());
assertEquals(2, res0.get(0).getValue());
}
{
List<Cache.Entry<Object, Object>> res1 = grid(1).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
assertTrue(res1.isEmpty());
}
{
List<Cache.Entry<Object, Object>> res1 = grid(10).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
assertTrue(res1.isEmpty());
}
}
}
use of org.apache.ignite.cache.CacheMode in project ignite by apache.
the class IgniteDataStructuresTestUtils method getAtomicConfigurations.
/**
* @return All variations of configurations according to backups and cache mode.
*/
public static Map<String, AtomicConfiguration> getAtomicConfigurations() {
Map<String, AtomicConfiguration> configs = new HashMap<>();
for (int backups : Arrays.asList(0, 1)) {
for (CacheMode cacheMode : CacheMode.values()) {
if (cacheMode == CacheMode.LOCAL) {
// TODO: https://issues.apache.org/jira/browse/IGNITE-13076
continue;
}
AtomicConfiguration cfg = new AtomicConfiguration().setBackups(backups).setCacheMode(cacheMode).setGroupName(cacheMode + "-grp-" + backups);
AtomicConfiguration old = configs.put("" + backups + cacheMode, cfg);
assert old == null : old;
}
}
return configs;
}
use of org.apache.ignite.cache.CacheMode in project ignite by apache.
the class CacheBlockOnReadAbstractTest method testUpdateBaselineTopologyTransactionalReplicated.
/**
* @throws Exception If failed.
*/
@Params(timeout = 5000L, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED)
@Test
public void testUpdateBaselineTopologyTransactionalReplicated() throws Exception {
doTest(asMessagePredicate(discoEvt -> {
if (discoEvt instanceof DiscoveryCustomEvent) {
DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
return customMsg instanceof ChangeGlobalStateMessage;
}
return false;
}), () -> {
startNodesInClientMode(false);
IgniteEx ignite = startGrid(UUID.randomUUID().toString());
baseline.get(0).cluster().setBaselineTopology(baseline.get(0).context().discovery().topologyVersion());
baseline.add(ignite);
});
}
use of org.apache.ignite.cache.CacheMode in project ignite by apache.
the class CacheBlockOnReadAbstractTest method testRestartBaselineTransactionalReplicated.
/**
* @throws Exception If failed.
*/
@Params(baseline = 4, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED)
@Test
public void testRestartBaselineTransactionalReplicated() throws Exception {
doTest(asMessagePredicate(discoEvt -> discoEvt.type() == EventType.EVT_NODE_JOINED), () -> {
IgniteEx node = baseline.get(baseline.size() - 1);
TestRecordingCommunicationSpi.spi(node).stopBlock();
stopGrid(node.name());
for (int i = 0; i < baselineServersCount() - 2; i++) cntFinishedReadOperations.countDown();
startGrid(node.name());
});
}
Aggregations