smiklosovic commented on code in PR #1351: URL: https://github.com/apache/cassandra/pull/1351#discussion_r857919243
########## test/distributed/org/apache/cassandra/distributed/test/DataResurrectionCheckTest.java: ########## @@ -0,0 +1,184 @@ +/* + * 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.cassandra.distributed.test; + +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.Test; + +import org.apache.cassandra.config.CassandraRelevantProperties; +import org.apache.cassandra.config.StartupChecksOptions; +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.api.IInvokableInstance; +import org.apache.cassandra.distributed.api.IIsolatedExecutor; +import org.apache.cassandra.exceptions.StartupException; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.service.DataResurrectionCheck; +import org.apache.cassandra.service.DataResurrectionCheck.Heartbeat; +import org.apache.cassandra.service.StartupChecks.StartupCheckType; +import org.apache.cassandra.utils.Clock.Global; + +import static java.lang.String.format; +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.cassandra.config.StartupChecksOptions.ENABLED_PROPERTY; +import static org.apache.cassandra.distributed.Cluster.build; +import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL; +import static org.apache.cassandra.service.DataResurrectionCheck.DEFAULT_HEARTBEAT_FILE; +import static org.apache.cassandra.service.DataResurrectionCheck.EXCLUDED_KEYSPACES_CONFIG_PROPERTY; +import static org.apache.cassandra.service.DataResurrectionCheck.EXCLUDED_TABLES_CONFIG_PROPERTY; +import static org.apache.cassandra.service.StartupChecks.StartupCheckType.check_data_resurrection; +import static org.awaitility.Awaitility.await; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class DataResurrectionCheckTest extends TestBaseImpl +{ + @Test + public void testDataResurrectionCheck() throws Exception + { + try + { + // set it to 1 hour so check will be not updated after it is written, for test purposes + System.setProperty(CassandraRelevantProperties.DATA_RESURRECTION_HEARTBEAT_PERIOD.getKey(), "3600000"); + + // start the node with the check enabled, it will just pass fine as there are not any user tables yet + // and system tables are young enough + try (Cluster cluster = build().withNodes(1) + .withDataDirCount(3) // we will expect heartbeat to be in the first data dir + .withConfig(config -> config.with(NATIVE_PROTOCOL) + .set("startup_checks", + getStartupChecksConfig(ENABLED_PROPERTY, "true"))) + .start()) + { + IInvokableInstance instance = cluster.get(1); + + checkHeartbeat(instance); + + for (String ks : new String[]{ "ks1", "ks2", "ks3" }) + { + cluster.schemaChange("CREATE KEYSPACE " + ks + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"); + cluster.schemaChange(format("CREATE TABLE %s.tb1 (pk text PRIMARY KEY) WITH gc_grace_seconds = 10", ks)); Review Comment: the whole "trick" is that this will not pass the check after 10 seconds by calling that check programmatically directly in the context of that instance. It was quite cumbersome to test this by any other strategy. I was thinking about "start -> stop -> wait to have some violations -> start -> check it does not start" but we would have to do it N times for each combination bellow and stopping of an instance will delete all its data dirs ... yuck. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org