Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: JUnit Jupiter migration from JUnit 4.x #959

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ subprojects {
testCompile 'org.jmockit:jmockit:1.38'
testCompile "org.spockframework:spock-core:1.1-groovy-2.4"
testCompile "com.google.truth:truth:1.0.1"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
4 changes: 2 additions & 2 deletions priam/src/test/java/com/netflix/priam/TestModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
import com.netflix.priam.utils.Sleeper;
import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.Registry;
import org.junit.Ignore;
import org.junit.jupiter.api.Disabled;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

@Ignore
@Disabled
public class TestModule extends AbstractModule {

@Override
Expand Down
91 changes: 46 additions & 45 deletions priam/src/test/java/com/netflix/priam/aws/TestRemoteBackupPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import java.nio.file.Paths;
import java.text.ParseException;
import java.time.Instant;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -60,13 +60,13 @@ public void testV1BackupPathsSST() throws ParseException {
abstractBackupPath.parseLocal(path.toFile(), BackupFileType.SST);

// Verify parse local
Assert.assertEquals(
Assertions.assertEquals(
0, abstractBackupPath.getLastModified().toEpochMilli()); // File do not exist.
Assert.assertEquals("keyspace1", abstractBackupPath.getKeyspace());
Assert.assertEquals("columnfamily1", abstractBackupPath.getColumnFamily());
Assert.assertEquals(BackupFileType.SST, abstractBackupPath.getType());
Assert.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assert.assertEquals(
Assertions.assertEquals("keyspace1", abstractBackupPath.getKeyspace());
Assertions.assertEquals("columnfamily1", abstractBackupPath.getColumnFamily());
Assertions.assertEquals(BackupFileType.SST, abstractBackupPath.getType());
Assertions.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assertions.assertEquals(
0,
abstractBackupPath
.getTime()
Expand All @@ -79,16 +79,16 @@ public void testV1BackupPathsSST() throws ParseException {
AbstractBackupPath abstractBackupPath2 = pathFactory.get();
abstractBackupPath2.parseRemote(remotePath);
validateAbstractBackupPath(abstractBackupPath, abstractBackupPath2);
Assert.assertEquals(abstractBackupPath.getTime(), abstractBackupPath2.getTime());
Assertions.assertEquals(abstractBackupPath.getTime(), abstractBackupPath2.getTime());
}

private void validateAbstractBackupPath(AbstractBackupPath abp1, AbstractBackupPath abp2) {
Assert.assertEquals(abp1.getKeyspace(), abp2.getKeyspace());
Assert.assertEquals(abp1.getColumnFamily(), abp2.getColumnFamily());
Assert.assertEquals(abp1.getFileName(), abp2.getFileName());
Assert.assertEquals(abp1.getType(), abp2.getType());
Assert.assertEquals(abp1.getCompression(), abp2.getCompression());
Assert.assertEquals(abp1.getEncryption(), abp2.getEncryption());
Assertions.assertEquals(abp1.getKeyspace(), abp2.getKeyspace());
Assertions.assertEquals(abp1.getColumnFamily(), abp2.getColumnFamily());
Assertions.assertEquals(abp1.getFileName(), abp2.getFileName());
Assertions.assertEquals(abp1.getType(), abp2.getType());
Assertions.assertEquals(abp1.getCompression(), abp2.getCompression());
Assertions.assertEquals(abp1.getEncryption(), abp2.getEncryption());
}

@Test
Expand All @@ -105,13 +105,13 @@ public void testV1BackupPathsSnap() throws ParseException {
abstractBackupPath.parseLocal(path.toFile(), BackupFileType.SNAP);

// Verify parse local
Assert.assertEquals(
Assertions.assertEquals(
0, abstractBackupPath.getLastModified().toEpochMilli()); // File do not exist.
Assert.assertEquals("keyspace1", abstractBackupPath.getKeyspace());
Assert.assertEquals("columnfamily1", abstractBackupPath.getColumnFamily());
Assert.assertEquals(BackupFileType.SNAP, abstractBackupPath.getType());
Assert.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assert.assertEquals(
Assertions.assertEquals("keyspace1", abstractBackupPath.getKeyspace());
Assertions.assertEquals("columnfamily1", abstractBackupPath.getColumnFamily());
Assertions.assertEquals(BackupFileType.SNAP, abstractBackupPath.getType());
Assertions.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assertions.assertEquals(
"201801011201", DateUtil.formatyyyyMMddHHmm(abstractBackupPath.getTime()));

// Verify toRemote and parseRemote.
Expand All @@ -121,7 +121,7 @@ public void testV1BackupPathsSnap() throws ParseException {
AbstractBackupPath abstractBackupPath2 = pathFactory.get();
abstractBackupPath2.parseRemote(remotePath);
validateAbstractBackupPath(abstractBackupPath, abstractBackupPath2);
Assert.assertEquals(abstractBackupPath.getTime(), abstractBackupPath2.getTime());
Assertions.assertEquals(abstractBackupPath.getTime(), abstractBackupPath2.getTime());
}

@Test
Expand All @@ -131,12 +131,12 @@ public void testV1BackupPathsMeta() throws ParseException {
abstractBackupPath.parseLocal(path.toFile(), BackupFileType.META);

// Verify parse local
Assert.assertEquals(
Assertions.assertEquals(
0, abstractBackupPath.getLastModified().toEpochMilli()); // File do not exist.
Assert.assertEquals(null, abstractBackupPath.getKeyspace());
Assert.assertEquals(null, abstractBackupPath.getColumnFamily());
Assert.assertEquals(BackupFileType.META, abstractBackupPath.getType());
Assert.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assertions.assertEquals(null, abstractBackupPath.getKeyspace());
Assertions.assertEquals(null, abstractBackupPath.getColumnFamily());
Assertions.assertEquals(BackupFileType.META, abstractBackupPath.getType());
Assertions.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());

// Verify toRemote and parseRemote.
String remotePath = abstractBackupPath.getRemotePath();
Expand All @@ -145,7 +145,7 @@ public void testV1BackupPathsMeta() throws ParseException {
AbstractBackupPath abstractBackupPath2 = pathFactory.get();
abstractBackupPath2.parseRemote(remotePath);
validateAbstractBackupPath(abstractBackupPath, abstractBackupPath2);
Assert.assertEquals(abstractBackupPath.getTime(), abstractBackupPath2.getTime());
Assertions.assertEquals(abstractBackupPath.getTime(), abstractBackupPath2.getTime());
}

@Test
Expand All @@ -161,13 +161,13 @@ public void testV2BackupPathSST() throws ParseException {
abstractBackupPath.parseLocal(path.toFile(), BackupFileType.SST_V2);

// Verify parse local
Assert.assertEquals(
Assertions.assertEquals(
0, abstractBackupPath.getLastModified().toEpochMilli()); // File do not exist.
Assert.assertEquals("keyspace1", abstractBackupPath.getKeyspace());
Assert.assertEquals("columnfamily1", abstractBackupPath.getColumnFamily());
Assert.assertEquals("SNAPPY", abstractBackupPath.getCompression().name());
Assert.assertEquals(BackupFileType.SST_V2, abstractBackupPath.getType());
Assert.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assertions.assertEquals("keyspace1", abstractBackupPath.getKeyspace());
Assertions.assertEquals("columnfamily1", abstractBackupPath.getColumnFamily());
Assertions.assertEquals("SNAPPY", abstractBackupPath.getCompression().name());
Assertions.assertEquals(BackupFileType.SST_V2, abstractBackupPath.getType());
Assertions.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());

// Verify toRemote and parseRemote.
Instant now = DateUtil.getInstant();
Expand All @@ -177,7 +177,7 @@ public void testV2BackupPathSST() throws ParseException {

AbstractBackupPath abstractBackupPath2 = pathFactory.get();
abstractBackupPath2.parseRemote(remotePath);
Assert.assertEquals(
Assertions.assertEquals(
now.toEpochMilli() / 1_000L * 1_000L,
abstractBackupPath2.getLastModified().toEpochMilli());
validateAbstractBackupPath(abstractBackupPath, abstractBackupPath2);
Expand All @@ -190,25 +190,26 @@ public void testV2BackupPathMeta() throws ParseException {
abstractBackupPath.parseLocal(path.toFile(), BackupFileType.META_V2);

// Verify parse local
Assert.assertEquals(
Assertions.assertEquals(
0, abstractBackupPath.getLastModified().toEpochMilli()); // File do not exist.
Assert.assertEquals(null, abstractBackupPath.getKeyspace());
Assert.assertEquals(null, abstractBackupPath.getColumnFamily());
Assert.assertEquals(BackupFileType.META_V2, abstractBackupPath.getType());
Assert.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assert.assertEquals(CryptographyAlgorithm.PLAINTEXT, abstractBackupPath.getEncryption());
Assertions.assertEquals(null, abstractBackupPath.getKeyspace());
Assertions.assertEquals(null, abstractBackupPath.getColumnFamily());
Assertions.assertEquals(BackupFileType.META_V2, abstractBackupPath.getType());
Assertions.assertEquals(path.toFile(), abstractBackupPath.getBackupFile());
Assertions.assertEquals(
CryptographyAlgorithm.PLAINTEXT, abstractBackupPath.getEncryption());

// Verify toRemote and parseRemote.
Instant now = DateUtil.getInstant();
abstractBackupPath.setLastModified(now);
String remotePath = abstractBackupPath.getRemotePath();
logger.info(remotePath);

Assert.assertEquals("SNAPPY", abstractBackupPath.getCompression().name());
Assertions.assertEquals("SNAPPY", abstractBackupPath.getCompression().name());

AbstractBackupPath abstractBackupPath2 = pathFactory.get();
abstractBackupPath2.parseRemote(remotePath);
Assert.assertEquals(
Assertions.assertEquals(
now.toEpochMilli() / 1_000L * 1_000L,
abstractBackupPath2.getLastModified().toEpochMilli());
validateAbstractBackupPath(abstractBackupPath, abstractBackupPath2);
Expand All @@ -218,12 +219,12 @@ public void testV2BackupPathMeta() throws ParseException {
public void testRemoteV2Prefix() throws ParseException {
Path path = Paths.get("test_backup");
AbstractBackupPath abstractBackupPath = pathFactory.get();
Assert.assertEquals(
Assertions.assertEquals(
"casstestbackup/1049_fake-app/1808575600/META_V2",
abstractBackupPath.remoteV2Prefix(path, BackupFileType.META_V2).toString());

path = Paths.get("s3-bucket-name", "fake_base_dir", "-6717_random_fake_app");
Assert.assertEquals(
Assertions.assertEquals(
"fake_base_dir/-6717_random_fake_app/1808575600/META_V2",
abstractBackupPath.remoteV2Prefix(path, BackupFileType.META_V2).toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.netflix.priam.config.IConfiguration;
import com.netflix.priam.identity.IMembership;
import com.netflix.priam.identity.IPriamInstanceFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/* Tests of {@link UpdateSecuritySettings.java} */
public class TestUpdateSecuritySettings {
Expand All @@ -22,7 +22,7 @@ public class TestUpdateSecuritySettings {
private FakeConfiguration config;
private FakeIPConverter ipConverter;

@Before
@BeforeEach
public void setUp() {
Injector injector = Guice.createInjector(new TestModule());
factory = injector.getInstance(IPriamInstanceFactory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.Registry;
import java.util.Collections;
import org.junit.Ignore;
import org.junit.jupiter.api.Disabled;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

@Ignore
@Disabled
public class BRTestModule extends AbstractModule {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@RunWith(Parameterized.class)
public class TestAbstractBackup {
private static final String COMPRESSED_DATA = "compressed-1234-Data.db";
private static final String COMPRESSION_INFO = "compressed-1234-CompressionInfo.db";
Expand All @@ -39,17 +37,17 @@ public class TestAbstractBackup {
RANDOM_COMPONENT);

private static final String DIRECTORY = "target/data/ks/cf/backup/";
private final AbstractBackup abstractBackup;
private final FakeConfiguration fakeConfiguration;
private final String tablePart;
private final CompressionType compressionAlgorithm;
private AbstractBackup abstractBackup;
private FakeConfiguration fakeConfiguration;
private String tablePart;
private CompressionType compressionAlgorithm;

@BeforeClass
@BeforeAll
public static void setUp() throws IOException {
FileUtils.forceMkdir(new File(DIRECTORY));
}

@Before
@BeforeEach
public void createFiles() throws IOException {
for (String tablePart : TABLE_PARTS) {
File file = Paths.get(DIRECTORY, tablePart).toFile();
Expand All @@ -61,12 +59,11 @@ public void createFiles() throws IOException {
}
}

@AfterClass
@AfterAll
public static void tearDown() throws IOException {
FileUtils.deleteDirectory(new File(DIRECTORY));
}

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
Expand All @@ -88,7 +85,8 @@ public static Collection<Object[]> data() {
});
}

public TestAbstractBackup(BackupsToCompress which, String tablePart, CompressionType algo) {
public void initTestAbstractBackup(
BackupsToCompress which, String tablePart, CompressionType algo) {
this.tablePart = tablePart;
this.compressionAlgorithm = algo;
Injector injector = Guice.createInjector(new BRTestModule());
Expand All @@ -111,8 +109,11 @@ public String getName() {
};
}

@Test
public void testCorrectCompressionType() throws Exception {
@MethodSource("data")
@ParameterizedTest
public void testCorrectCompressionType(
BackupsToCompress which, String tablePart, CompressionType algo) throws Exception {
initTestAbstractBackup(which, tablePart, algo);
File parent = new File(DIRECTORY);
AbstractBackupPath.BackupFileType backupFileType = AbstractBackupPath.BackupFileType.SST_V2;
ImmutableSet<AbstractBackupPath> paths =
Expand Down