use of org.apache.ignite.internal.util.typedef.PAX in project ignite by apache.
the class GridCacheQueueCleanupSelfTest method testCleanup.
/**
* @throws Exception If failed.
*/
@Test
public void testCleanup() throws Exception {
IgniteQueue<Integer> queue = grid(0).queue(QUEUE_NAME1, 0, config(false));
GridCacheContext cctx = GridTestUtils.getFieldValue(queue, "cctx");
final String queueCacheName = cctx.name();
ClusterNode node = grid(0).affinity(queueCacheName).mapKeyToNode(new GridCacheQueueHeaderKey(QUEUE_NAME1));
final Ignite ignite = grid(0).localNode().equals(node) ? grid(1) : grid(0);
/*
assertNotNull(queue);
// Add/poll some items.
for (int i = 0; i < 500; i++)
queue.add(i);
for (int i = 0; i < 10; i++)
queue.poll();
assertTrue(!queue.isEmpty());
// Kill node containing queue header.
final String killGridName = node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME);
stopGrid(killGridName);
assertNull(((IgniteKernal)grid).cache(DEFAULT_CACHE_NAME).dataStructures().queue(QUEUE_NAME1, 0, false, false));
final AtomicBoolean stop = new AtomicBoolean(false);
GridFuture<?> fut1;
GridFuture<?> fut2;
try {
// Start threads using cache concurrently with cleanup thread.
fut1 = startAddPollThread(grid, stop, QUEUE_NAME1);
fut2 = startAddPollThread(grid, stop, QUEUE_NAME2);
U.sleep(3000); // Give some time for cleanup thread.
}
finally {
stop.set(true);
}
fut1.get();
fut2.get();
((IgniteKernal)grid).cache(DEFAULT_CACHE_NAME).dataStructures().removeQueue(QUEUE_NAME1);
((IgniteKernal)grid).cache(DEFAULT_CACHE_NAME).dataStructures().removeQueue(QUEUE_NAME2);
assertTrue(GridTestUtils.waitForCondition(new PAX() {
@Override public boolean applyx() {
for (int i = 0; i < gridCount(); i++) {
if (getTestIgniteInstanceName(i).equals(killGridName))
continue;
Iterator<GridCacheEntryEx<Object, Object>> entries =
((GridKernal)grid(i)).context().cache().internalCache(DEFAULT_CACHE_NAME).map().allEntries0().iterator();
if (entries.hasNext()) {
log.info("Found cache entries, will wait: " + entries.next());
return false;
}
}
return true;
}
}, 5000));
startGrid(killGridName);
// Create queue again.
queue = ((IgniteKernal)grid).cache(DEFAULT_CACHE_NAME).dataStructures().queue(QUEUE_NAME1, 0, false, true);
*/
assertEquals(0, queue.size());
for (int i = 0; i < 500; i++) queue.add(i);
assertEquals(500, queue.size());
// Remove queue and create queue with the same name.
queue.close();
queue = ignite.queue(QUEUE_NAME1, 0, config(false));
assertEquals(0, queue.size());
for (int i = 0; i < 500; i++) queue.add(i);
assertEquals(500, queue.size());
// Check that items of removed queue are removed, items of new queue not.
assertTrue(GridTestUtils.waitForCondition(new PAX() {
@Override
public boolean applyx() throws IgniteCheckedException {
int cnt = 0;
for (int i = 0; i < gridCount(); i++) {
GridCacheAdapter<Object, Object> cache = grid(i).context().cache().internalCache(queueCacheName);
for (Object e : cache.localEntries(new CachePeekMode[] { CachePeekMode.ALL })) cnt++;
}
if (cnt > 501) {
// 500 items + header.
log.info("Found more cache entries than expected, will wait: " + cnt);
return false;
}
return true;
}
}, 5000));
for (int i = 0; i < 500; i++) assertEquals((Integer) i, queue.poll());
}
use of org.apache.ignite.internal.util.typedef.PAX in project ignite by apache.
the class GridP2PUserVersionChangeSelfTest method testCacheRedeployVersionChangeContinuousMode.
/**
* @throws Exception If failed.
*/
@Ignore("https://issues.apache.org/jira/browse/IGNITE-604")
@Test
public void testCacheRedeployVersionChangeContinuousMode() throws Exception {
depMode = DeploymentMode.CONTINUOUS;
try {
Ignite ignite1 = startGrid("testCacheRedeployVersionChangeContinuousMode1");
Ignite ignite2 = startGrid("testCacheRedeployVersionChangeContinuousMode2");
GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, Collections.singletonMap("META-INF/ignite.xml", makeUserVersion("1").getBytes()));
Class rcrsCls = ldr.loadClass(TEST_RCRS_NAME);
IgniteCache<Long, Object> cache1 = ignite1.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache1);
cache1.put(1L, rcrsCls.newInstance());
final IgniteCache<Long, Object> cache2 = ignite2.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache2);
// need to use condition wait.
assert GridTestUtils.waitForCondition(new PAX() {
@Override
public boolean applyx() {
return cache2.get(1L) != null;
}
}, getConditionTimeout());
stopGrid("testCacheRedeployVersionChangeContinuousMode1");
// Increase the user version of the test class.
ldr.setResourceMap(Collections.singletonMap("META-INF/ignite.xml", makeUserVersion("2").getBytes()));
ignite1 = startGrid("testCacheRedeployVersionChangeContinuousMode1");
cache1 = ignite1.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache1);
// Put an entry with a new user version.
cache1.put(2L, rcrsCls.newInstance());
// and removed from cache asynchronously.
assert GridTestUtils.waitForCondition(new PAX() {
@Override
public boolean applyx() {
return cache2.get(1L) == null;
}
}, getConditionTimeout()) : "2nd condition failed [entries1=" + toSet(cache1.iterator()) + ", entries2=" + toSet(cache2.iterator()) + ']';
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.util.typedef.PAX in project ignite by apache.
the class IgniteDataStorageMetricsSelfTest method testPersistenceMetrics.
/**
* @throws Exception if failed.
*/
@Test
public void testPersistenceMetrics() throws Exception {
final IgniteEx ig = startGrid(0);
ig.active(true);
try {
IgniteCache<Object, Object> cache = ig.cache("cache");
for (int i = 0; i < 10; i++) cache.put(i, new Person("first-" + i, "last-" + i));
IgniteCache<Object, Object> cacheNp = ig.cache("cache-np");
for (int i = 0; i < 10; i++) cacheNp.put(i, new Person("first-" + i, "last-" + i));
DataRegionMetrics memMetrics = ig.dataRegionMetrics("dflt-plc");
assertNotNull(memMetrics);
assertTrue(memMetrics.getDirtyPages() > 0);
assertTrue(memMetrics.getPagesFillFactor() > 0);
memMetrics = ig.dataRegionMetrics("no-persistence");
assertNotNull(memMetrics);
assertTrue(memMetrics.getTotalAllocatedPages() > 0);
assertTrue(memMetrics.getPagesFillFactor() > 0);
ig.context().cache().context().database().waitForCheckpoint("test");
assertTrue(waitForCondition(new PAX() {
@Override
public boolean applyx() {
DataStorageMetrics pMetrics = ig.dataStorageMetrics();
assertNotNull(pMetrics);
return pMetrics.getLastCheckpointTotalPagesNumber() != 0 && pMetrics.getLastCheckpointDataPagesNumber() != 0;
}
}, 10_000));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.util.typedef.PAX in project ignite by apache.
the class CacheContinuousQueryFailoverAbstractSelfTest method testRemoteFilter.
/**
* @throws Exception If failed.
*/
@Test
public void testRemoteFilter() throws Exception {
this.backups = 2;
final int SRV_NODES = 4;
startGridsMultiThreaded(SRV_NODES);
Ignite qryClient = startClientGrid(SRV_NODES);
IgniteCache<Object, Object> qryClientCache = qryClient.cache(DEFAULT_CACHE_NAME);
if (cacheMode() != REPLICATED)
assertEquals(backups, qryClientCache.getConfiguration(CacheConfiguration.class).getBackups());
Affinity<Object> aff = qryClient.affinity(DEFAULT_CACHE_NAME);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
final CacheEventListener3 lsnr = asyncCallback() ? new CacheEventAsyncListener3() : new CacheEventListener3();
qry.setLocalListener(lsnr);
qry.setRemoteFilter(lsnr);
int PARTS = 10;
QueryCursor<?> cur = qryClientCache.query(qry);
Map<Object, T2<Object, Object>> updates = new HashMap<>();
final List<T3<Object, Object, Object>> expEvts = new ArrayList<>();
for (int i = 0; i < (atomicityMode() == CacheAtomicityMode.ATOMIC ? SRV_NODES - 1 : SRV_NODES - 2); i++) {
log.info("Stop iteration: " + i);
TestCommunicationSpi spi = (TestCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
Ignite ignite = ignite(i);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
List<Integer> keys = testKeys(cache, PARTS);
boolean first = true;
boolean filtered = false;
for (Integer key : keys) {
log.info("Put [node=" + ignite.name() + ", key=" + key + ", part=" + aff.partition(key) + ", filtered=" + filtered + ']');
T2<Object, Object> t = updates.get(key);
Integer val = filtered ? (key % 2 == 0 ? key + 1 : key) : key * 2;
if (t == null) {
updates.put(key, new T2<>((Object) val, null));
if (!filtered)
expEvts.add(new T3<>((Object) key, (Object) val, null));
} else {
updates.put(key, new T2<>((Object) val, (Object) key));
if (!filtered)
expEvts.add(new T3<>((Object) key, (Object) val, (Object) key));
}
cache.put(key, val);
if (first) {
spi.skipMsg = true;
first = false;
}
filtered = !filtered;
}
stopGrid(i);
boolean check = GridTestUtils.waitForCondition(new PAX() {
@Override
public boolean applyx() throws IgniteCheckedException {
return expEvts.size() == lsnr.keys.size();
}
}, 5000L);
if (!check) {
Set<Integer> keys0 = new HashSet<>(keys);
keys0.removeAll(lsnr.keys);
log.info("Missed events for keys: " + keys0);
fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + keys0.size() + ']');
}
checkEvents(expEvts, lsnr, false);
}
cur.close();
}
Aggregations