|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.cassandra.tools.nodetool; |
| 19 | + |
| 20 | +import org.junit.BeforeClass; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +import org.apache.cassandra.cql3.CQLTester; |
| 24 | +import org.apache.cassandra.service.CacheService; |
| 25 | +import org.apache.cassandra.tools.ToolRunner; |
| 26 | + |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; |
| 28 | + |
| 29 | +public class SetCachePeriodTest extends CQLTester |
| 30 | +{ |
| 31 | + private static CacheService cacheService; |
| 32 | + |
| 33 | + @BeforeClass |
| 34 | + public static void setup() throws Exception |
| 35 | + { |
| 36 | + requireNetwork(); |
| 37 | + startJMXServer(); |
| 38 | + cacheService = CacheService.instance; |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testHelp() |
| 43 | + { |
| 44 | + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("help", "setcacheperiod"); |
| 45 | + tool.assertOnExitCode(); |
| 46 | + |
| 47 | + String help = "NAME\n" + |
| 48 | + " nodetool setcacheperiod - Set global key, row, and counter cache period\n" + |
| 49 | + " in second units\n" + |
| 50 | + "\n" + |
| 51 | + "SYNOPSIS\n" + |
| 52 | + " nodetool [(-h <host> | --host <host>)] [(-p <port> | --port <port>)]\n" + |
| 53 | + " [(-pp | --print-port)] [(-pw <password> | --password <password>)]\n" + |
| 54 | + " [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]\n" + |
| 55 | + " [(-u <username> | --username <username>)] setcacheperiod [--]\n" + |
| 56 | + " <key-cache-period> <row-cache-period> <counter-cache-period>\n" + |
| 57 | + "\n" + |
| 58 | + "OPTIONS\n" + |
| 59 | + " -h <host>, --host <host>\n" + |
| 60 | + " Node hostname or ip address\n" + |
| 61 | + "\n" + |
| 62 | + " -p <port>, --port <port>\n" + |
| 63 | + " Remote jmx agent port number\n" + |
| 64 | + "\n" + |
| 65 | + " -pp, --print-port\n" + |
| 66 | + " Operate in 4.0 mode with hosts disambiguated by port number\n" + |
| 67 | + "\n" + |
| 68 | + " -pw <password>, --password <password>\n" + |
| 69 | + " Remote jmx agent password\n" + |
| 70 | + "\n" + |
| 71 | + " -pwf <passwordFilePath>, --password-file <passwordFilePath>\n" + |
| 72 | + " Path to the JMX password file\n" + |
| 73 | + "\n" + |
| 74 | + " -u <username>, --username <username>\n" + |
| 75 | + " Remote jmx agent username\n" + |
| 76 | + "\n" + |
| 77 | + " --\n" + |
| 78 | + " This option can be used to separate command-line options from the\n" + |
| 79 | + " list of argument, (useful when arguments might be mistaken for\n" + |
| 80 | + " command-line options\n" + |
| 81 | + "\n" + |
| 82 | + " <key-cache-period> <row-cache-period> <counter-cache-period>\n" + |
| 83 | + " Key cache, row cache, and counter period in second units\n" + |
| 84 | + "\n" + |
| 85 | + "\n"; |
| 86 | + assertThat(tool.getStdout()).isEqualTo(help); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testOptionalParameters() |
| 91 | + { |
| 92 | + int keyPeriodSetting = 333; |
| 93 | + int rowPeriodSetting = 444; |
| 94 | + int counterPeriodSetting = 555; |
| 95 | + ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("setcacheperiod", |
| 96 | + String.valueOf(keyPeriodSetting), |
| 97 | + String.valueOf(rowPeriodSetting), |
| 98 | + String.valueOf(counterPeriodSetting)); |
| 99 | + tool.assertOnCleanExit(); |
| 100 | + assertThat(tool.getStdout()).isEmpty(); |
| 101 | + |
| 102 | + assertThat(cacheService.getKeyCacheSavePeriodInSeconds()).isEqualTo(keyPeriodSetting); |
| 103 | + assertThat(cacheService.getRowCacheSavePeriodInSeconds()).isEqualTo(rowPeriodSetting); |
| 104 | + assertThat(cacheService.getCounterCacheSavePeriodInSeconds()).isEqualTo(counterPeriodSetting); |
| 105 | + } |
| 106 | +} |
0 commit comments