use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class DeploymentRequestOfUnknownClassProcessingTest method testResponseReceivingOnDeploymentRequestOfUnknownClass.
/**
* @throws Exception If failed.
*/
@Test
public void testResponseReceivingOnDeploymentRequestOfUnknownClass() throws Exception {
IgniteEx locNode = grid(0);
IgniteEx remNode = grid(1);
// Register deployment on remote node for attemt to load class on request receiving
GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) });
Class task = ldr.loadClass("org.apache.ignite.tests.p2p.P2PTestTaskExternalPath1");
GridDeployment locDep = remNode.context().deploy().deploy(task, task.getClassLoader());
final GridFutureAdapter<Void> testResultFut = new GridFutureAdapter<>();
final LogListener remNodeLogLsnr = LogListener.matches(s -> s.matches("Failed to resolve class.*?" + UNKNOWN_CLASS_NAME + ".*")).build();
remNodeLog.registerListener(remNodeLogLsnr);
locNode.context().io().addMessageListener(TEST_TOPIC_NAME, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
try {
assertTrue(msg instanceof GridDeploymentResponse);
GridDeploymentResponse resp = (GridDeploymentResponse) msg;
assertFalse("Unexpected response result, success=" + resp.success(), resp.success());
String errMsg = resp.errorMessage();
assertNotNull("Response should contain an error message.", errMsg);
assertTrue("Response contains unexpected error message, errorMessage=" + errMsg, errMsg.matches("Requested resource not found \\(ignoring locally\\).*?" + UNKNOWN_CLASS_NAME + ".*"));
testResultFut.onDone();
} catch (Error e) {
testResultFut.onDone(e);
}
}
});
GridDeploymentRequest req = new GridDeploymentRequest(TEST_TOPIC_NAME, locDep.classLoaderId(), UNKNOWN_CLASS_NAME, false);
req.responseTopicBytes(U.marshal(locNode.context(), req.responseTopic()));
locNode.context().io().sendToGridTopic(remNode.localNode(), TOPIC_CLASSLOAD, req, GridIoPolicy.P2P_POOL);
// Сhecks that the expected response has been received.
testResultFut.get(5_000, TimeUnit.MILLISECONDS);
// Checks that error has been logged on remote node.
assertTrue(remNodeLogLsnr.check());
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class DiagnosticLogForPartitionStatesTest method doTest.
/**
* @param cfgs Cache configurations.
* @param msgExp {@code true} if warning message is expected.
* @throws Exception If failed.
*/
private void doTest(List<CacheConfiguration<Integer, Integer>> cfgs, boolean msgExp) throws Exception {
String name = (cfgs.size() == 1) ? cfgs.get(0).getName() : cfgs.get(0).getGroupName();
LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(PARTITION_STATE_FAILED_MSG, name, ANY_MSG))).times(msgExp ? 1 : 0).build();
log.registerListener(lsnr);
IgniteEx node1 = startGrid(0);
IgniteEx node2 = startGrid(1);
node1.cluster().active(true);
List<IgniteCache<Integer, Integer>> caches = cfgs.stream().map(cfg -> node1.getOrCreateCache(cfg)).collect(Collectors.toList());
Map<String, Set<Integer>> clearKeys = new HashMap<>();
for (IgniteCache<Integer, Integer> cache : caches) {
String cacheName = cache.getName();
Set<Integer> clr = new HashSet<>();
for (int i = 0; i < 100; i++) {
cache.put(i, i);
if (node2.affinity(cacheName).isPrimary(node2.localNode(), i))
clr.add(i);
}
clearKeys.put(cacheName, clr);
}
for (IgniteCache<Integer, Integer> c : caches) {
node2.context().cache().cache(c.getName()).clearLocallyAll(clearKeys.get(c.getName()), true, true, true);
}
// Trigger partition map exchange and therefore trigger partitions validation.
startGrid(2);
awaitPartitionMapExchange();
assertTrue(lsnr.check());
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class ConsistentIdImplicitlyExplicitlyTest method testConsistentIdNotConfiguredWithPersistence.
/**
* Consistent ID is not configurent neither in the {@link IgniteConfiguration} nor in the JVM property, and
* persistent enabled.
*
* @throws Exception if failed.
*/
@Test
public void testConsistentIdNotConfiguredWithPersistence() throws Exception {
persistenceEnabled = true;
LogListener lsnr = expectLogEvent(WARN_MESSAGE, 1);
Ignite ignite = startGrid(0);
assertNull(ignite.configuration().getConsistentId());
assertTrue(UUID_PATTERN.matcher(ignite.cluster().localNode().consistentId().toString()).find());
assertTrue(lsnr.check());
info("Consistent ID: " + ignite.cluster().localNode().consistentId());
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class ConsistentIdImplicitlyExplicitlyTest method expectLogEvent.
/**
* @param eventMsg Event message.
* @param cnt Number of expected events.
*/
private LogListener expectLogEvent(String eventMsg, int cnt) {
LogListener lsnr = LogListener.matches(s -> s.startsWith(eventMsg)).times(cnt).build();
log.registerListener(lsnr);
return lsnr;
}
use of org.apache.ignite.testframework.LogListener in project ignite by apache.
the class ConsistentIdImplicitlyExplicitlyTest method testConsistentIdNotConfigured.
/**
* Consistent ID is not configured neither in the {@link IgniteConfiguration} nor via the JVM property.
*
* @throws Exception if failed.
*/
@Test
public void testConsistentIdNotConfigured() throws Exception {
LogListener lsnr = expectLogEvent(WARN_MESSAGE, 0);
Ignite ignite = startGrid(0);
assertNull(ignite.configuration().getConsistentId());
assertTrue(ADDR_WITH_PORT_PATTERN.matcher(ignite.cluster().localNode().consistentId().toString()).find());
assertTrue(lsnr.check());
info("Consistent ID: " + ignite.cluster().localNode().consistentId());
}
Aggregations