|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.ignite.util; |
| 19 | + |
| 20 | +import java.io.File; |
| 21 | +import java.nio.file.Files; |
| 22 | +import java.nio.file.Path; |
| 23 | +import java.nio.file.Paths; |
| 24 | +import java.util.regex.Matcher; |
| 25 | +import org.apache.ignite.IgniteCheckedException; |
| 26 | +import org.apache.ignite.configuration.IgniteConfiguration; |
| 27 | +import org.apache.ignite.internal.util.typedef.internal.U; |
| 28 | +import org.junit.Test; |
| 29 | + |
| 30 | +import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; |
| 31 | +import static org.apache.ignite.testframework.GridTestUtils.assertContains; |
| 32 | +import static org.apache.ignite.util.GridCommandHandlerClusterByClassTest.dumpFileNameMatcher; |
| 33 | + |
| 34 | +/** */ |
| 35 | +public class IdleVerifyDumpTest extends GridCommandHandlerClusterByClassAbstractTest { |
| 36 | + /** {@inheritDoc} */ |
| 37 | + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { |
| 38 | + return super.getConfiguration(igniteInstanceName) |
| 39 | + .setWorkDirectory(nodeWorkDirectory(igniteInstanceName)); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Test ensuring that idle verify dump output file is created exactly |
| 44 | + * on server node specified via the --host parameter. |
| 45 | + */ |
| 46 | + @Test |
| 47 | + public void testDumpResultMatchesConnection() throws Exception { |
| 48 | + injectTestSystemOut(); |
| 49 | + |
| 50 | + client.createCache(DEFAULT_CACHE_NAME).put(1, 1); |
| 51 | + |
| 52 | + checkDump(0); |
| 53 | + |
| 54 | + checkDump(1); |
| 55 | + } |
| 56 | + |
| 57 | + /** */ |
| 58 | + private void checkDump(int nodeIdx) throws Exception { |
| 59 | + assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", "--port", connectorPort(grid(nodeIdx)))); |
| 60 | + |
| 61 | + Matcher fileNameMatcher = dumpFileNameMatcher(); |
| 62 | + |
| 63 | + assertTrue(fileNameMatcher.find()); |
| 64 | + |
| 65 | + Path dumpFileName = Paths.get(fileNameMatcher.group(1)); |
| 66 | + |
| 67 | + String dumpRes = new String(Files.readAllBytes(dumpFileName)); |
| 68 | + |
| 69 | + assertContains(log, dumpRes, "The check procedure has finished, no conflicts have been found."); |
| 70 | + |
| 71 | + assertContains(log, dumpFileName.toString(), nodeWorkDirectory(getTestIgniteInstanceName(nodeIdx))); |
| 72 | + } |
| 73 | + |
| 74 | + /** */ |
| 75 | + private String nodeWorkDirectory(String igniteInstanceName) throws IgniteCheckedException { |
| 76 | + return new File(U.defaultWorkDirectory(), igniteInstanceName).getAbsolutePath(); |
| 77 | + } |
| 78 | +} |
0 commit comments