frankgh commented on a change in pull request #1428: URL: https://github.com/apache/cassandra/pull/1428#discussion_r798052678
########## File path: test/unit/org/apache/cassandra/db/virtual/GossipStateTransitionsTableTest.java ########## @@ -0,0 +1,96 @@ +/* + * 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.db.virtual; + +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.cql3.UntypedResultSet; +import org.apache.cassandra.gms.Gossiper; +import org.apache.cassandra.utils.FBUtilities; + +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the {@link GossipStateTransitionsTable} virtual table. + */ +public class GossipStateTransitionsTableTest extends CQLTester +{ + private static final String KS_NAME = "vts"; + + @SuppressWarnings("FieldCanBeLocal") + private VirtualTable table; + + @BeforeClass + public static void setup() throws Exception + { + // limit the transitions to record to 2 per host + DatabaseDescriptor.setMaxGossipStateTransitionsSize(2); + setUpClass(); + startJMXServer(); + } + + @Before + public void config() + { + table = new GossipStateTransitionsTable(KS_NAME); + VirtualKeyspaceRegistry.instance.register(new VirtualKeyspace(KS_NAME, ImmutableList.of(table))); + } + + @Test + public void testSelectAllWhenNoGossipStateTransitionsHaveBeenRecorded() throws Throwable + { + assertEmpty(execute("SELECT * FROM vts.gossip_state_transitions")); + } + + @Test + public void testSelectAllWithStateTransitions() throws Throwable + { + long testStartMillis = currentTimeMillis(); + try + { + requireNetwork(); // triggers gossip state transitions + + UntypedResultSet resultSet = execute("SELECT * FROM vts.gossip_state_transitions"); + + assertThat(resultSet.size()).isGreaterThan(0) + .isLessThanOrEqualTo(2); + + for (UntypedResultSet.Row row : resultSet) + { + assertThat(row.getColumns().size()).isEqualTo(24); + assertThat(row.getTimestamp("timestamp").getTime()).isGreaterThan(testStartMillis) + .isLessThan(currentTimeMillis()); Review comment: I believe `nanoTime()` can go backwards; millis is guaranteed to at least not go backwards. I actually forget which one is guaranteed. But I agree that this is risky, so I will think about something for this ########## File path: test/unit/org/apache/cassandra/gms/GossiperTest.java ########## @@ -190,6 +191,7 @@ public void testLargeGenerationJump() throws UnknownHostException, InterruptedEx { // clean up the gossip states Gossiper.instance.endpointStateMap.clear(); + Gossiper.instance.gossipStateTransitionMap.clear(); Review comment: sounds good -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

