skoppu22 commented on code in PR #169: URL: https://github.com/apache/cassandra-analytics/pull/169#discussion_r2988921441
########## cassandra-analytics-common/src/test/java/org/apache/cassandra/bridge/CassandraVersionTest.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.bridge; + +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for CassandraVersion SSTable version methods + */ +public class CassandraVersionTest +{ + @Test + void testFromSSTableVersionFourZeroNativeVersions() + { + Optional<CassandraVersion> result = CassandraVersion.fromSSTableVersion("big-na"); + assertThat(result).isPresent(); + assertThat(result.get()).isEqualTo(CassandraVersion.FOURZERO); + + result = CassandraVersion.fromSSTableVersion("big-nb"); + assertThat(result).isPresent(); + assertThat(result.get()).isEqualTo(CassandraVersion.FOURZERO); + } + + @Test + void testFromSSTableVersionFiveZeroNativeVersions() + { + Optional<CassandraVersion> result = CassandraVersion.fromSSTableVersion("big-oa"); + assertThat(result).isPresent(); + assertThat(result.get()).isEqualTo(CassandraVersion.FIVEZERO); + + result = CassandraVersion.fromSSTableVersion("bti-da"); + assertThat(result).isPresent(); + assertThat(result.get()).isEqualTo(CassandraVersion.FIVEZERO); + } + + @Test + void testFromSSTableVersionThreeZeroNativeVersions() + { + Optional<CassandraVersion> result = CassandraVersion.fromSSTableVersion("big-ma"); + assertThat(result).isPresent(); + assertThat(result.get()).isEqualTo(CassandraVersion.THREEZERO); + } + + @Test + void testFromSSTableVersionUnknownVersion() + { + Optional<CassandraVersion> result = CassandraVersion.fromSSTableVersion("unknown-xx"); + assertThat(result).isEmpty(); + } + + @Test + void testFromSSTableVersionNullVersion() + { + Optional<CassandraVersion> result = CassandraVersion.fromSSTableVersion(null); + assertThat(result).isEmpty(); + } + + @Test + void testGetSupportedSStableVersionsForReadFourZero() + { + Set<String> supported = CassandraVersion.FOURZERO.getSupportedSStableVersionsForRead(); + + // C* 4.0 can read its own versions + assertThat(supported).contains("big-na", "big-nb"); + + // C* 4.0 can read C* 3.0 versions (previous major version family) + assertThat(supported).contains("big-ma", "big-mb", "big-mc", "big-md", "big-me", "big-mf"); + + // C* 4.0 cannot read C* 5.0 versions + assertThat(supported).doesNotContain("big-oa", "bti-da"); + } + + @Test + void testGetSupportedSStableVersionsForReadFiveZero() + { + Set<String> supported = CassandraVersion.FIVEZERO.getSupportedSStableVersionsForRead(); + + // C* 5.0 can read its own versions + assertThat(supported).contains("big-oa", "bti-da"); + + // C* 5.0 can read C* 4.0 and 4.1 versions (previous major version family) + assertThat(supported).contains("big-na", "big-nb"); + + // C* 5.0 cannot read C* 3.0 versions (not in previous major version family) + assertThat(supported).doesNotContain("big-ma", "big-mb", "big-mc", "big-md", "big-me", "big-mf"); + } + + @Test + void testGetSupportedSStableVersionsForReadThreeZero() + { + Set<String> supported = CassandraVersion.THREEZERO.getSupportedSStableVersionsForRead(); + + // C* 3.0 can read its own versions + assertThat(supported).contains("big-ma", "big-mb", "big-mc", "big-md", "big-me", "big-mf"); + + // C* 3.0 cannot read C* 4.0+ versions + assertThat(supported).doesNotContain("big-na", "big-nb", "big-oa", "bti-da"); + + // C* 3.0's previous major version (2.x) is not defined, so only its own versions are readable + assertThat(supported).hasSize(6); // Only the 6 native 3.0 versions + } + + @Test + void testGetSupportedSStableVersionsForReadFourOne() + { + Set<String> supported = CassandraVersion.FOURONE.getSupportedSStableVersionsForRead(); + + // C* 4.1 has no native SSTable versions of its own, but can read C* 4.0 and C* 3.0 versions + // C* 4.1 can read C* 4.0 versions (same major version family) + assertThat(supported).contains("big-na", "big-nb"); + + // C* 4.1 can read C* 3.0 versions (previous major version family) + assertThat(supported).contains("big-ma", "big-mb", "big-mc", "big-md", "big-me", "big-mf"); + + // C* 4.1 cannot read C* 5.0 versions + assertThat(supported).doesNotContain("big-oa", "bti-da"); + } + + @Test + void testGetNativeSStableVersionsFourZero() + { + List<String> nativeVersions = CassandraVersion.FOURZERO.getNativeSStableVersions(); + assertThat(nativeVersions).containsExactlyInAnyOrder("big-na", "big-nb"); + } + + @Test + void testGetNativeSStableVersionsFiveZero() + { + List<String> nativeVersions = CassandraVersion.FIVEZERO.getNativeSStableVersions(); + assertThat(nativeVersions).containsExactlyInAnyOrder("big-oa", "bti-da"); + } + + @Test + void testGetNativeSStableVersionsFourOneEmpty() + { + // C* 4.1 did not introduce new native SSTable versions + List<String> nativeVersions = CassandraVersion.FOURONE.getNativeSStableVersions(); + assertThat(nativeVersions).isEmpty(); + } + + @Test + void testGetSSTableVersionIndexValidVersion() + { + int index = CassandraVersion.FOURZERO.getSSTableVersionIndex("big-na"); + assertThat(index).isEqualTo(0); Review Comment: Removed this test -- 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]
