use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.
the class IgniteClientDataStructuresAbstractTest method testQueue.
/**
* @param creator Creator node.
* @param other Other node.
* @throws Exception If failed.
*/
private void testQueue(Ignite creator, final Ignite other) throws Exception {
assertNull(creator.queue("q1", 0, null));
assertNull(other.queue("q1", 0, null));
try (IgniteQueue<Integer> queue = creator.queue("q1", 0, new CollectionConfiguration())) {
assertNotNull(queue);
queue.add(1);
assertEquals(1, queue.poll().intValue());
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
U.sleep(1000);
IgniteQueue<Integer> queue0 = other.queue("q1", 0, null);
assertEquals(0, queue0.size());
log.info("Add in queue.");
queue0.add(2);
return null;
}
});
log.info("Try take.");
assertEquals(2, queue.take().intValue());
log.info("Finished take.");
fut.get();
}
assertNull(creator.queue("q1", 0, null));
assertNull(other.queue("q1", 0, null));
}
use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.
the class GridCacheSetAbstractSelfTest method testAffinityRun.
/**
* @throws Exception If failed.
*/
public void testAffinityRun() throws Exception {
final CollectionConfiguration colCfg = collectionConfiguration();
colCfg.setCollocated(false);
colCfg.setCacheMode(CacheMode.PARTITIONED);
try (final IgniteSet<Integer> set1 = grid(0).set("Set1", colCfg)) {
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
set1.affinityRun(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
return null;
}
}, IgniteException.class, "Failed to execute affinityRun() for non-collocated set: " + set1.name() + ". This operation is supported only for collocated sets.");
}
colCfg.setCollocated(true);
try (final IgniteSet<Integer> set2 = grid(0).set("Set2", colCfg)) {
set2.add(100);
set2.affinityRun(new IgniteRunnable() {
@IgniteInstanceResource
private IgniteEx ignite;
@Override
public void run() {
assertTrue(ignite.cachex("datastructures_0").affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Set2"));
assertEquals(100, set2.iterator().next().intValue());
}
});
}
}
use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.
the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method testAddFailover.
/**
* @param collocated Collocation flag.
* @throws Exception If failed.
*/
private void testAddFailover(boolean collocated) throws Exception {
CollectionConfiguration colCfg = config(collocated);
IgniteQueue<Integer> queue = grid(0).queue(QUEUE_NAME, 0, colCfg);
assertNotNull(queue);
assertEquals(0, queue.size());
int primaryNode = primaryQueueNode(queue);
int testNodeIdx = -1;
for (int i = 0; i < gridCount(); i++) {
if (i != primaryNode)
testNodeIdx = i;
}
log.info("Test node: " + testNodeIdx);
log.info("Header primary node: " + primaryNode);
queue = grid(testNodeIdx).queue(QUEUE_NAME, 0, null);
assertNotNull(queue);
// Kill queue header's primary node .
testAddFailover(queue, Arrays.asList(primaryNode));
List<Integer> killIdxs = new ArrayList<>();
for (int i = 0; i < gridCount(); i++) {
if (i != testNodeIdx)
killIdxs.add(i);
}
// Kill random node.
testAddFailover(queue, killIdxs);
}
use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.
the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method collectionConfiguration.
/** {@inheritDoc} */
@Override
protected CollectionConfiguration collectionConfiguration() {
CollectionConfiguration colCfg = super.collectionConfiguration();
colCfg.setBackups(1);
return colCfg;
}
use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method dataStructureOperationsTest.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void dataStructureOperationsTest() throws Exception {
clientMode = true;
final Ignite client = startGrid(serverCount());
doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check atomic long.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.atomicLong("testAtomic", 41, true);
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.atomicLong("testAtomic", 41, true);
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteAtomicLong atomicLong = (IgniteAtomicLong) o;
assertEquals(42, atomicLong.incrementAndGet());
return true;
}
}), // Check set.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.set("testSet", new CollectionConfiguration());
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.set("testSet", new CollectionConfiguration());
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteSet set = (IgniteSet) o;
String val = "testVal";
set.add(val);
assertEquals(1, set.size());
assertTrue(set.contains(val));
return true;
}
}), // Check ignite queue.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.queue("TestQueue", 10, new CollectionConfiguration());
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.queue("TestQueue", 10, new CollectionConfiguration());
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteQueue queue = (IgniteQueue) o;
String val = "Test";
queue.add(val);
assertEquals(val, queue.poll());
return true;
}
})));
clientMode = false;
}
Aggregations