use of org.apache.ignite.lifecycle.LifecycleBean in project ignite by apache.
the class SpringCacheManagerContextInjectionTest method testBeanInjectionUsingConfigPath.
/**
* @throws Exception If failed.
*/
public void testBeanInjectionUsingConfigPath() throws Exception {
new AnnotationConfigApplicationContext(TestPathConfiguration.class);
Ignite grid = IgnitionEx.grid("springInjectionTest");
IgniteConfiguration cfg = grid.configuration();
LifecycleBean[] beans = cfg.getLifecycleBeans();
assertEquals(2, beans.length);
TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean) beans[0];
TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean) beans[1];
bean1.checkState();
bean2.checkState();
}
use of org.apache.ignite.lifecycle.LifecycleBean in project ignite by apache.
the class IgniteExchangeLatchManagerDiscoHistoryTest method testProperException.
/**
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = IGNITE_DISCOVERY_HISTORY_SIZE, value = DISCO_HISTORY_SIZE)
public void testProperException() throws Exception {
final IgniteEx crd = startGrid(0);
final CountDownLatch exchangeLatch = new CountDownLatch(1);
final CountDownLatch startSrvsLatch = new CountDownLatch(1);
final AtomicReference<Exception> err = new AtomicReference<>();
// Lifecycle bean that is used to register PartitionsExchangeAware listener.
lifecycleBean = new LifecycleBean() {
/**
* Ignite instance.
*/
@IgniteInstanceResource
IgniteEx ignite;
/**
* {@inheritDoc}
*/
@Override
public void onLifecycleEvent(LifecycleEventType evt) throws IgniteException {
if (evt == LifecycleEventType.BEFORE_NODE_START) {
// The goal is registering PartitionsExchangeAware listener before the discovery manager is started.
ignite.context().internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {
@Override
public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
ignite.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {
/**
* {@inheritDoc}
*/
@Override
public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
try {
// Let's start nodes.
startSrvsLatch.countDown();
// Blocks the initial exchange and waits for other nodes.
exchangeLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
err.compareAndSet(null, e);
}
}
});
}
});
}
}
};
// Start server node with short topology history.
victim = true;
GridTestUtils.runAsync(() -> startGrid(1));
// Waits for the initial exchange.
startSrvsLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
victim = false;
lifecycleBean = null;
List<IgniteInternalFuture> srvFuts = new ArrayList<>(TOPOLOGY_HISTORY_SIZE);
try {
// Major topology version that is corresponding to the start of the node with short topology history.
final long topVer = 2;
// Starting server nodes to exhaust the topology history.
for (int i = 2; i < 3 * TOPOLOGY_HISTORY_SIZE && !disco.isEmptyTopologyHistory(topVer); ++i) {
final int currNodeIdx = i;
final int joinedNodesCnt = disco.totalJoinedNodes();
srvFuts.add(GridTestUtils.runAsync(() -> startGrid(currNodeIdx)));
assertTrue("Failed to wait for a new server node [joinedNodesCnt=" + joinedNodesCnt + "]", GridTestUtils.waitForCondition(() -> disco.totalJoinedNodes() >= (joinedNodesCnt + 1), DEFAULT_TIMEOUT));
}
assertTrue("Disco cache history is not empty for the topology [majorTopVer=" + topVer + ']', disco.isEmptyTopologyHistory(topVer));
// Let's continue the ongoing exchange.
exchangeLatch.countDown();
boolean failureHnd = GridTestUtils.waitForCondition(() -> cpFailureCtx.get() != null, DEFAULT_TIMEOUT);
assertNull("Unexpected exception (probably, the topology history still exists [err=" + err + ']', err.get());
assertTrue("Failure handler was not triggered.", failureHnd);
// Check that IgniteException was thrown instead of NullPointerException.
assertTrue("IgniteException must be thrown.", X.hasCause(cpFailureCtx.get().error(), IgniteException.class));
// Check that message contains a hint to fix the issue.
GridTestUtils.assertContains(log, cpFailureCtx.get().error().getMessage(), "Consider increasing IGNITE_DISCOVERY_HISTORY_SIZE property. Current value is " + DISCO_HISTORY_SIZE);
} finally {
IgnitionEx.stop(getTestIgniteInstanceName(1), true, ShutdownPolicy.IMMEDIATE, true);
srvFuts.forEach(f -> {
try {
f.get(DEFAULT_TIMEOUT);
} catch (IgniteCheckedException e) {
err.compareAndSet(null, e);
}
});
}
assertNull("Unexpected exception [err=" + err.get() + ']', err.get());
}
use of org.apache.ignite.lifecycle.LifecycleBean in project ignite by apache.
the class GridCachePartitionExchangeManagerWarningsTest method testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager.
/**
*/
@Test
public void testDumpLongRunningOperationsWaitForFullyInitializedExchangeManager() throws Exception {
long waitingTimeout = 5_000;
PrintStream errStream = System.err;
CountDownLatch startLatch = new CountDownLatch(1);
CountDownLatch waitLatch = new CountDownLatch(1);
try {
// GridCachePartitionExchangeManager#dumpLongRunningOperations() uses diagnostic log,
// which can be non-initialized, and so, error messgaes are logged into standard error output stream.
ByteArrayOutputStream testOut = new ByteArrayOutputStream(16 * 1024);
System.setErr(new PrintStream(testOut));
AtomicReference<IgniteInternalFuture<?>> dumpOpsFut = new AtomicReference<>();
IgniteInternalFuture<Ignite> startFut = null;
// Lyficycle bean allows to register DatabaseLifecycleListener and trigger dumpLongRunningOperations
// before GridCachePartitionExchangeManager is started.
lifecycleBean = new LifecycleBean() {
/**
* Ignite instance.
*/
@IgniteInstanceResource
IgniteEx ignite;
/**
* {@inheritDoc}
*/
@Override
public void onLifecycleEvent(LifecycleEventType evt) throws IgniteException {
if (evt == LifecycleEventType.BEFORE_NODE_START) {
ignite.context().internalSubscriptionProcessor().registerDatabaseListener(new DatabaseLifecycleListener() {
@Override
public void onInitDataRegions(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException {
dumpOpsFut.set(GridTestUtils.runAsync(() -> ignite.context().cache().context().exchange().dumpLongRunningOperations(1_000)));
// Let's allow to check that dumpLongRunningOperations is triggered.
startLatch.countDown();
// Wait for the check
try {
if (!waitLatch.await(waitingTimeout * 3, TimeUnit.MILLISECONDS))
throw new IgniteCheckedException("Failed to wait for a check of dumpLongRunningOperations");
} catch (InterruptedException e) {
throw new IgniteCheckedException(e);
}
}
});
}
}
};
startFut = GridTestUtils.runAsync(new Callable<Ignite>() {
@Override
public Ignite call() throws Exception {
return startGrid(0);
}
});
assertTrue("Server node did not start in " + waitingTimeout + " ms.", startLatch.await(waitingTimeout, TimeUnit.MILLISECONDS));
// Check that dumpLongRunningOperations did not produce any error.
if (GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout)) {
// Check that error output stream does not contain NullPointerException.
String output = testOut.toString();
assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
}
// Unblock starting the node.
waitLatch.countDown();
assertTrue("Dumping log running operations is not completed yet.", GridTestUtils.waitForCondition(() -> dumpOpsFut.get().isDone(), waitingTimeout));
// Check that error output stream does not contain any error.
String output = testOut.toString();
assertTrue("Unexpected error [err=" + output + ']', output.isEmpty());
startFut.get(waitingTimeout, TimeUnit.MILLISECONDS);
} finally {
startLatch.countDown();
waitLatch.countDown();
System.setErr(errStream);
}
}
use of org.apache.ignite.lifecycle.LifecycleBean in project ignite by apache.
the class GridCacheDhtPreloadUnloadSelfTest method testUnloadOneBackThreeNodesWithLifeCycleBean.
/**
* @throws Exception If failed.
*/
@Test
public void testUnloadOneBackThreeNodesWithLifeCycleBean() throws Exception {
preloadMode = SYNC;
backups = 1;
try {
final int cnt = 1000;
lbean = new LifecycleBean() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public void onLifecycleEvent(LifecycleEventType evt) {
if (evt == LifecycleEventType.AFTER_NODE_START) {
IgniteCache<Integer, String> c = ignite.cache(DEFAULT_CACHE_NAME);
if (c.putIfAbsent(-1, "true")) {
populate(ignite.<Integer, String>cache(DEFAULT_CACHE_NAME), cnt);
info(">>> POPULATED GRID <<<");
}
}
}
};
int gridCnt = 3;
for (int i = 0; i < gridCnt; i++) {
startGrid(i);
for (int j = 0; j < i; j++) info("Grid size [i=" + i + ", size=" + grid(j).cache(DEFAULT_CACHE_NAME).localSize() + ']');
}
long wait = 3000;
waitForUnload(gridCnt, cnt, wait);
} finally {
lbean = null;
stopAllGrids();
}
}
use of org.apache.ignite.lifecycle.LifecycleBean in project ignite by apache.
the class SpringTransactionManagerContextInjectionTest method testBeanInjectionUsingConfigPath.
/**
* @throws Exception If failed.
*/
public void testBeanInjectionUsingConfigPath() throws Exception {
BeanFactory factory = new AnnotationConfigApplicationContext(TestPathConfiguration.class);
Ignite grid = IgnitionEx.grid("springInjectionTest");
IgniteConfiguration cfg = grid.configuration();
LifecycleBean[] beans = cfg.getLifecycleBeans();
assertEquals(2, beans.length);
TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean) beans[0];
TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean) beans[1];
bean1.checkState();
bean2.checkState();
}
Aggregations