wernerdv commented on code in PR #12547: URL: https://github.com/apache/ignite/pull/12547#discussion_r2610074776
########## modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerCheckpointTest.java: ########## @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.util; + +import java.util.Objects; +import java.util.regex.Pattern; + +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.ListeningTestLogger; +import org.apache.ignite.testframework.LogListener; +import org.junit.Test; + +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR; + +/** Test for checkpoint in control.sh command. */ +public class GridCommandHandlerCheckpointTest extends GridCommandHandlerAbstractTest { + /** */ + protected final ListeningTestLogger listeningLog = new ListeningTestLogger(log); + + /** */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + if (!persistenceEnable()) + cfg.setDataStorageConfiguration(null); + + cfg.setGridLogger(listeningLog); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + stopAllGrids(); + cleanPersistenceDir(); + injectTestSystemOut(); + } + + /** Test checkpoint command with persistence enabled. */ + @Test + public void testCheckpointPersistenceCluster() throws Exception { + persistenceEnable(true); + + IgniteEx srv = startGrids(2); + IgniteEx cli = startClientGrid("client"); + + LogListener checkpointFinishedLsnr = LogListener.matches("Checkpoint finished").build(); + listeningLog.registerListener(checkpointFinishedLsnr); + + srv.cluster().state(ClusterState.ACTIVE); + + IgniteCache<Integer, Integer> cacheSrv = srv.getOrCreateCache(DEFAULT_CACHE_NAME); + IgniteCache<Integer, Integer> cacheCli = cli.getOrCreateCache(DEFAULT_CACHE_NAME); + + cacheSrv.put(1, 1); + cacheCli.put(1, 1); + + assertEquals(EXIT_CODE_OK, execute("--checkpoint")); + + String out = testOut.toString(); + assertFalse(out.contains(cli.localNode().id().toString())); + assertFalse(out.contains(Objects.toString(cli.localNode().consistentId()))); + + outputContains("Checkpoint triggered on all nodes"); + assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000)); + + testOut.reset(); + checkpointFinishedLsnr.reset(); + + cacheSrv.put(2, 2); + cacheCli.put(2, 2); + + assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--reason", "test_reason")); + outputContains("Checkpoint triggered on all nodes"); + + assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000)); + testOut.reset(); + checkpointFinishedLsnr.reset(); + + cacheSrv.put(3, 3); + cacheCli.put(3, 3); + + assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--wait-for-finish")); + outputContains("Checkpoint triggered on all nodes"); + + assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000)); + checkpointFinishedLsnr.reset(); + } + + /** Test checkpoint command with in-memory cluster. */ + @Test + public void testCheckpointInMemoryCluster() throws Exception { + persistenceEnable(false); + + LogListener checkpointFinishedLsnr = LogListener.matches("Checkpoint finished").build(); + listeningLog.registerListener(checkpointFinishedLsnr); + + IgniteEx srv = startGrids(2); + IgniteEx cli = startClientGrid("client"); + + srv.cluster().state(ClusterState.ACTIVE); + + srv.createCache("testCache"); + assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--checkpoint")); + + String out = testOut.toString(); Review Comment: Let's move it after the line `outputContains(...)`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
