|
84 | 84 | import org.apache.ignite.metric.MetricRegistry; |
85 | 85 | import org.apache.ignite.spi.metric.LongMetric; |
86 | 86 | import org.apache.ignite.testframework.GridTestUtils; |
| 87 | +import org.apache.ignite.testframework.ListeningTestLogger; |
| 88 | +import org.apache.ignite.testframework.LogListener; |
87 | 89 | import org.apache.ignite.transactions.Transaction; |
88 | 90 | import org.jetbrains.annotations.Nullable; |
89 | 91 | import org.junit.Before; |
@@ -1311,6 +1313,116 @@ public void testClientHandlesSnapshotFailOnStartStage() throws Exception { |
1311 | 1313 | assertSnapshotCacheKeys(cln.cache(dfltCacheCfg.getName())); |
1312 | 1314 | } |
1313 | 1315 |
|
| 1316 | + /** |
| 1317 | + * Test snapshot operation logging for incremental snapshots. |
| 1318 | + */ |
| 1319 | + @Test |
| 1320 | + public void testIncrementalSnapshotOperationLogging() throws Exception { |
| 1321 | + assumeFalse("https://issues.apache.org/jira/browse/IGNITE-17819", encryption); |
| 1322 | + |
| 1323 | + int gridsCnt = 2; |
| 1324 | + ListeningTestLogger[] listeningLogs = new ListeningTestLogger[gridsCnt]; |
| 1325 | + IgniteEx ignite = null; |
| 1326 | + |
| 1327 | + for (int i = 0; i < gridsCnt; ++i) { |
| 1328 | + listeningLogs[i] = new ListeningTestLogger(log); |
| 1329 | + |
| 1330 | + IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(i)) |
| 1331 | + .setGridLogger(listeningLogs[i]); |
| 1332 | + |
| 1333 | + if (ignite == null) |
| 1334 | + ignite = startGrid(cfg); |
| 1335 | + else |
| 1336 | + startGrid(cfg); |
| 1337 | + } |
| 1338 | + ignite.cluster().state(ACTIVE); |
| 1339 | + |
| 1340 | + LogListener[] fullStartListeners = new LogListener[gridsCnt]; |
| 1341 | + LogListener[] fullEndListeners = new LogListener[gridsCnt]; |
| 1342 | + |
| 1343 | + for (int i = 0; i < gridsCnt; ++i) { |
| 1344 | + fullStartListeners[i] = LogListener.matches("Starting local snapshot operation") |
| 1345 | + .andMatches("incremental=false") |
| 1346 | + .build(); |
| 1347 | + |
| 1348 | + fullEndListeners[i] = LogListener.matches("Finishing local snapshot operation") |
| 1349 | + .andMatches("err=null") |
| 1350 | + .andMatches("incremental=false") |
| 1351 | + .build(); |
| 1352 | + |
| 1353 | + listeningLogs[i].registerListener(fullStartListeners[i]); |
| 1354 | + listeningLogs[i].registerListener(fullEndListeners[i]); |
| 1355 | + } |
| 1356 | + |
| 1357 | + ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(getTestTimeout()); |
| 1358 | + |
| 1359 | + for (int i = 0; i < gridsCnt; i++) { |
| 1360 | + assertTrue("Full snapshot start log not found on node " + i, |
| 1361 | + fullStartListeners[i].check()); |
| 1362 | + assertTrue("Full snapshot end log not found on node " + i, |
| 1363 | + fullEndListeners[i].check()); |
| 1364 | + } |
| 1365 | + |
| 1366 | + LogListener[] incStartListeners = new LogListener[gridsCnt]; |
| 1367 | + LogListener[] incEndListeners = new LogListener[gridsCnt]; |
| 1368 | + |
| 1369 | + for (int i = 0; i < gridsCnt; i++) { |
| 1370 | + incStartListeners[i] = LogListener.matches("Starting local snapshot operation") |
| 1371 | + .andMatches("incremental=true") |
| 1372 | + .andMatches("incIdx=1") |
| 1373 | + .build(); |
| 1374 | + |
| 1375 | + incEndListeners[i] = LogListener.matches("Finishing local snapshot operation") |
| 1376 | + .andMatches("err=null") |
| 1377 | + .andMatches("incremental=true") |
| 1378 | + .andMatches("incIdx=1") |
| 1379 | + .build(); |
| 1380 | + |
| 1381 | + listeningLogs[i].registerListener(incStartListeners[i]); |
| 1382 | + listeningLogs[i].registerListener(incEndListeners[i]); |
| 1383 | + } |
| 1384 | + |
| 1385 | + ignite.snapshot().createIncrementalSnapshot(SNAPSHOT_NAME).get(getTestTimeout()); |
| 1386 | + |
| 1387 | + for (int i = 0; i < gridsCnt; i++) { |
| 1388 | + assertTrue("Incremental snapshot start log not found on node " + i, |
| 1389 | + incStartListeners[i].check()); |
| 1390 | + assertTrue("Incremental snapshot end log not found on node " + i, |
| 1391 | + incEndListeners[i].check()); |
| 1392 | + } |
| 1393 | + |
| 1394 | + LogListener[] failureListeners = new LogListener[gridsCnt]; |
| 1395 | + |
| 1396 | + for (int i = 0; i < gridsCnt; i++) { |
| 1397 | + failureListeners[i] = LogListener.matches("Finishing local snapshot operation") |
| 1398 | + .andMatches("Snapshot process failure for testing") |
| 1399 | + .build(); |
| 1400 | + |
| 1401 | + listeningLogs[i].registerListener(failureListeners[i]); |
| 1402 | + } |
| 1403 | + |
| 1404 | + snp(ignite).localSnapshotSenderFactory(sft -> { |
| 1405 | + throw new IgniteException("Snapshot process failure for testing"); |
| 1406 | + }); |
| 1407 | + |
| 1408 | + try { |
| 1409 | + IgniteFuture<Void> fut = ignite.snapshot().createSnapshot("testSnp2"); |
| 1410 | + |
| 1411 | + fut.get(); |
| 1412 | + fail("Should have failed"); |
| 1413 | + } |
| 1414 | + catch (Exception e) { |
| 1415 | + // No-op. |
| 1416 | + } |
| 1417 | + |
| 1418 | + stopAllGrids(); |
| 1419 | + |
| 1420 | + for (int i = 0; i < gridsCnt; i++) { |
| 1421 | + assertTrue("Failure snapshot log not found on node " + i, |
| 1422 | + failureListeners[i].check()); |
| 1423 | + } |
| 1424 | + } |
| 1425 | + |
1314 | 1426 | /** |
1315 | 1427 | * @param ignite Ignite instance. |
1316 | 1428 | * @param started Latch will be released when delta partition processing starts. |
|
0 commit comments