JeetKunDoug commented on code in PR #80: URL: https://github.com/apache/cassandra-analytics/pull/80#discussion_r1765194312
########## cassandra-analytics-core/src/test/java/org/apache/cassandra/spark/bulkwriter/CassandraClusterInfoTest.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.spark.bulkwriter; + +import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.util.Collections; +import java.util.concurrent.CompletableFuture; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Range; +import org.junit.jupiter.api.Test; + +import o.a.c.sidecar.client.shaded.common.response.TimeSkewResponse; +import org.apache.cassandra.spark.bulkwriter.token.TokenRangeMapping; +import org.apache.cassandra.spark.exception.TimeSkewTooLargeException; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class CassandraClusterInfoTest +{ + @Test + void testTimeSkewAcceptable() + { + Instant localNow = Instant.now(); + int allowanceMinutes = 10; + Instant remoteNow = localNow.plus(Duration.ofMinutes(1)); + CassandraClusterInfo ci = mockClusterInfoForTimeSkewTest(allowanceMinutes, remoteNow); + ci.validateTimeSkewWithLocalNow(Range.openClosed(BigInteger.valueOf(10), BigInteger.valueOf(20)), localNow); + } + + @Test + void testTimeSkewTooLarge() + { + Instant localNow = Instant.now(); + int allowanceMinutes = 10; + Instant remoteNow = localNow.plus(Duration.ofMinutes(11)); // 11 > allowanceMinutes + CassandraClusterInfo ci = mockClusterInfoForTimeSkewTest(allowanceMinutes, remoteNow); + assertThatThrownBy(() -> ci.validateTimeSkewWithLocalNow(Range.openClosed(BigInteger.valueOf(10), BigInteger.valueOf(20)), localNow)) + .isExactlyInstanceOf(TimeSkewTooLargeException.class); + } Review Comment: NIT: I'm not crazy about tests that have no asserts, even if it's really just "this doesn't throw" - a suggestion to make the test just a bit more explicit about what it's testing: ```suggestion public static final Range<BigInteger> RANGE = Range.openClosed(BigInteger.valueOf(10), BigInteger.valueOf(20)); @Test void testTimeSkewAcceptable() { Instant localNow = Instant.now(); int allowanceMinutes = 10; Instant remoteNow = localNow.plus(Duration.ofMinutes(1)); CassandraClusterInfo ci = mockClusterInfoForTimeSkewTest(allowanceMinutes, remoteNow); assertThatNoException().describedAs("Acceptable time skew should validate without exception") .isThrownBy(() -> ci.validateTimeSkewWithLocalNow(RANGE, localNow)); } @Test void testTimeSkewTooLarge() { Instant localNow = Instant.now(); int allowanceMinutes = 10; Instant remoteNow = localNow.plus(Duration.ofMinutes(11)); // 11 > allowanceMinutes CassandraClusterInfo ci = mockClusterInfoForTimeSkewTest(allowanceMinutes, remoteNow); assertThatException().describedAs("Time skew with too large a value should throw TimeSkewTooLargeException") .isThrownBy(() -> ci.validateTimeSkewWithLocalNow(RANGE, localNow)) .isExactlyInstanceOf(TimeSkewTooLargeException.class); } ``` -- 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: commits-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org