Skip to content

Commit

Permalink
SQUASH add VersionsTest
Browse files Browse the repository at this point in the history
 - fixes pattern
 - handles non-existant build directory
 - reduces some method visibilities
 - adds dummy jar files for testing against
  • Loading branch information
michaelsembwever committed May 15, 2021
1 parent 5a01754 commit 1c937fa
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ doc/source/tools/nodetool

# Python virtual environment
venv/
/nbproject/
27 changes: 7 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -122,7 +118,6 @@
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>0.13</version>
<configuration>
<addLicenseHeaders>true</addLicenseHeaders>
</configuration>
Expand Down Expand Up @@ -152,20 +147,13 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemProperties>
<cassandra.test.dtest_jar_path>src/test/resources/example-build-dir</cassandra.test.dtest_jar_path>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -174,7 +162,6 @@
<connection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf/cassandra-in-jvm-dtest-api.git</url>
<tag>0.0.6</tag>
</scm>
</project>

25 changes: 14 additions & 11 deletions src/main/java/org/apache/cassandra/distributed/shared/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Versions
public final class Versions
{
private static final Logger logger = LoggerFactory.getLogger(Versions.class);

Expand Down Expand Up @@ -153,7 +153,7 @@ public Version(Major major, String version, URL[] classpath)

private final Map<Major, List<Version>> versions;

public Versions(Map<Major, List<Version>> versions)
private Versions(Map<Major, List<Version>> versions)
{
this.versions = versions;
}
Expand All @@ -177,19 +177,22 @@ public static Versions find()
final String dtestJarDirectory = System.getProperty(PROPERTY_PREFIX + "test.dtest_jar_path", "build");
final File sourceDirectory = new File(dtestJarDirectory);
logger.info("Looking for dtest jars in " + sourceDirectory.getAbsolutePath());
final Pattern pattern = Pattern.compile("dtest-(?<fullversion>(\\d+)\\.(\\d+)(\\.\\d+)?(\\.\\d+)?)([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?\\.jar");
final Pattern pattern = Pattern.compile("dtest-(?<fullversion>(\\d+)\\.(\\d+)(\\.|-alpha|-beta|-rc)([0-9]+)?(\\.\\d+)?)([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?\\.jar");
final Map<Major, List<Version>> versions = new HashMap<>();
for (Major major : Major.values())
versions.put(major, new ArrayList<>());

for (File file : sourceDirectory.listFiles())
if (sourceDirectory.exists())
{
Matcher m = pattern.matcher(file.getName());
if (!m.matches())
continue;
String version = m.group(1);
Major major = Major.fromFull(version);
versions.get(major).add(new Version(major, version, new URL[]{ toURL(file) }));
for (File file : sourceDirectory.listFiles())
{
Matcher m = pattern.matcher(file.getName());
if (!m.matches())
continue;
String version = m.group(1);
Major major = Major.fromFull(version);
versions.get(major).add(new Version(major, version, new URL[]{ toURL(file) }));
}
}

for (Map.Entry<Major, List<Version>> e : versions.entrySet())
Expand All @@ -203,7 +206,7 @@ public static Versions find()
return new Versions(versions);
}

public static URL toURL(File file)
private static URL toURL(File file)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed 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.shared;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class VersionsTest
{

@Test
public void testGet()
{
Versions.find().get("2.2.2");
}

@Test
public void testGetLatest()
{
Versions.find().getLatest(Versions.Major.v22);
}

@Test
public void testFind()
{
Versions versions = Versions.find();
assertThat(versions).isNotNull();

}

@Test
public void testToURL()
{
assertThat(Versions.getClassPath()).isNotEmpty();
}

}
2 changes: 2 additions & 0 deletions src/test/resources/example-build-dir/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Empty jar files to be used in VersionsTest

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 1c937fa

Please sign in to comment.