Skip to content
Permalink
Browse files
Migrate all tests to JUnit5
  • Loading branch information
DomGarguilo committed Mar 24, 2022
1 parent 333873d commit bf88eb15601fc6317616e8a252fce702d74c3b7a
Showing 11 changed files with 103 additions and 104 deletions.
12 pom.xml
@@ -107,12 +107,6 @@
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.accumulo</groupId>
<artifactId>accumulo-minicluster</artifactId>
@@ -123,6 +117,12 @@
<artifactId>accumulo-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
@@ -18,10 +18,11 @@

import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.BufferedWriter;
import java.io.File;
@@ -75,10 +76,9 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.google.common.collect.Iterators;

@@ -100,7 +100,7 @@ public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoo
cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, "false");
}

@Before
@BeforeEach
public void setupTest() throws Exception {
c = Accumulo.newClient().from(getClientProps()).build();
String user = c.whoami();
@@ -111,7 +111,7 @@ public void setupTest() throws Exception {
String passwd = new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8);
writeClientPropsFile(getClientPropsFile(), instance, keepers, user, passwd);
} else {
Assert.fail("Unknown token type: " + token);
fail("Unknown token type: " + token);
}
fs = getCluster().getFileSystem();
dir = new Path(cluster.getTemporaryPath(), getClass().getName()).toString();
@@ -120,7 +120,7 @@ public void setupTest() throws Exception {
c.securityOperations().changeUserAuthorizations(user, new Authorizations(auths.split(",")));
}

@After
@AfterEach
public void teardownTest() throws Exception {
if (null != origAuths) {
c.securityOperations().changeUserAuthorizations(getAdminPrincipal(), origAuths);
@@ -186,21 +186,21 @@ public void testStatsCombiner() throws Exception {
bw.flush();

Iterator<Entry<Key,Value>> iter = c.createScanner(table, Authorizations.EMPTY).iterator();
assertTrue("Iterator had no results", iter.hasNext());
assertTrue(iter.hasNext(), "Iterator had no results");
Entry<Key,Value> e = iter.next();
assertEquals("Results ", "1,3,4,2", e.getValue().toString());
assertFalse("Iterator had additional results", iter.hasNext());
assertEquals("1,3,4,2", e.getValue().toString(), "Results ");
assertFalse(iter.hasNext(), "Iterator had additional results");

m = new Mutation("foo");
m.put("a", "b", "0,20,20,2");
bw.addMutation(m);
bw.close();

iter = c.createScanner(table, Authorizations.EMPTY).iterator();
assertTrue("Iterator had no results", iter.hasNext());
assertTrue(iter.hasNext(), "Iterator had no results");
e = iter.next();
assertEquals("Results ", "0,20,24,4", e.getValue().toString());
assertFalse("Iterator had additional results", iter.hasNext());
assertEquals("0,20,24,4", e.getValue().toString(), "Results ");
assertFalse(iter.hasNext(), "Iterator had additional results");
}

@Test
@@ -220,8 +220,10 @@ public void testShardedIndex() throws Exception {
// should find ourselves
boolean thisFile = false;
for (String file : found) {
if (file.endsWith("/ExamplesIT.java"))
if (file.endsWith("/ExamplesIT.java")) {
thisFile = true;
break;
}
}
assertTrue(thisFile);

@@ -280,7 +282,7 @@ public void testWordCount() throws Exception {
assumeTrue(getAdminToken() instanceof PasswordToken);
Path readme = new Path(new Path(System.getProperty("user.dir")), "README.md");
if (!new File(readme.toString()).exists()) {
Assert.fail("README.md does not exist!");
fail("README.md does not exist!");
}
fs.copyFromLocalFile(readme, new Path(dir + "/tmp/wc/README.md"));
String[] args = new String[] {"-c", getClientPropsFile(), "-i", dir + "/tmp/wc", "-t",
@@ -333,6 +335,6 @@ private void goodExec(Class<?> theClass, String... args) throws IOException {
// We're already slurping stdout into memory (not redirecting to file). Might as well add it
// to error message.
pair = getClusterControl().execWithStdout(theClass, args);
Assert.assertEquals("stdout=" + pair.getValue(), 0, pair.getKey().intValue());
assertEquals(0, pair.getKey().intValue(), "stdout=" + pair.getValue());
}
}
@@ -16,13 +16,13 @@
*/
package org.apache.accumulo.examples.constraints;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.io.Text;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableList;

@@ -16,13 +16,13 @@
*/
package org.apache.accumulo.examples.constraints;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.io.Text;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.google.common.collect.Iterables;

@@ -16,8 +16,8 @@
*/
package org.apache.accumulo.examples.dirlist;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.util.ArrayList;
import java.util.Map.Entry;
@@ -39,9 +39,9 @@
import org.apache.accumulo.test.functional.ConfigurableMacBase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CountIT extends ConfigurableMacBase {

@@ -53,7 +53,7 @@ protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSit
cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, "false");
}

@Before
@BeforeEach
public void setupInstance() throws Exception {
tableName = getUniqueNames(1)[0];
client = Accumulo.newClient().from(getClientProperties()).build();
@@ -75,7 +75,7 @@ public void setupInstance() throws Exception {
bw.close();
}

@After
@AfterEach
public void teardown() {
client.close();
}
@@ -16,6 +16,11 @@
*/
package org.apache.accumulo.examples.filedata;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
@@ -33,10 +38,10 @@
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import junit.framework.TestCase;

public class ChunkCombinerTest extends TestCase {
public class ChunkCombinerTest {

public static class MapIterator implements SortedKeyValueIterator<Key,Value> {
private Iterator<Entry<Key,Value>> iter;
@@ -76,7 +81,7 @@ public boolean hasTop() {
}

@Override
public void next() throws IOException {
public void next() {
entry = null;
while (iter.hasNext()) {
entry = iter.next();
@@ -92,8 +97,7 @@ public void next() throws IOException {
}

@Override
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive)
throws IOException {
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) {
if (!inclusive) {
throw new IllegalArgumentException("can only do inclusive colf filtering");
}
@@ -114,43 +118,34 @@ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean i

@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options,
IteratorEnvironment env) throws IOException {
IteratorEnvironment env) {
throw new UnsupportedOperationException();
}
}

private TreeMap<Key,Value> row1;
private TreeMap<Key,Value> row2;
private TreeMap<Key,Value> row3;
private TreeMap<Key,Value> allRows;
private static TreeMap<Key,Value> allRows;

private TreeMap<Key,Value> cRow1;
private TreeMap<Key,Value> cRow2;
private TreeMap<Key,Value> cRow3;
private TreeMap<Key,Value> allCRows;
private static TreeMap<Key,Value> allCRows;

private TreeMap<Key,Value> cOnlyRow1;
private TreeMap<Key,Value> cOnlyRow2;
private TreeMap<Key,Value> cOnlyRow3;
private TreeMap<Key,Value> allCOnlyRows;
private static TreeMap<Key,Value> allCOnlyRows;

private TreeMap<Key,Value> badrow;
private static TreeMap<Key,Value> badrow;

@Override
protected void setUp() {
row1 = new TreeMap<>();
row2 = new TreeMap<>();
row3 = new TreeMap<>();
@BeforeAll
protected static void setUp() {
TreeMap<Key,Value> row1 = new TreeMap<>();
TreeMap<Key,Value> row2 = new TreeMap<>();
TreeMap<Key,Value> row3 = new TreeMap<>();
allRows = new TreeMap<>();

cRow1 = new TreeMap<>();
cRow2 = new TreeMap<>();
cRow3 = new TreeMap<>();
TreeMap<Key,Value> cRow1 = new TreeMap<>();
TreeMap<Key,Value> cRow2 = new TreeMap<>();
TreeMap<Key,Value> cRow3 = new TreeMap<>();
allCRows = new TreeMap<>();

cOnlyRow1 = new TreeMap<>();
cOnlyRow2 = new TreeMap<>();
cOnlyRow3 = new TreeMap<>();
TreeMap<Key,Value> cOnlyRow1 = new TreeMap<>();
TreeMap<Key,Value> cOnlyRow2 = new TreeMap<>();
TreeMap<Key,Value> cOnlyRow3 = new TreeMap<>();
allCOnlyRows = new TreeMap<>();

badrow = new TreeMap<>();
@@ -225,6 +220,7 @@ protected void setUp() {

private static final Collection<ByteSequence> emptyColfs = new HashSet<>();

@Test
public void test1() throws IOException {
runTest(false, allRows, allCRows, emptyColfs);
runTest(true, allRows, allCRows, emptyColfs);
@@ -250,7 +246,7 @@ private void runTest(boolean reseek, TreeMap<Key,Value> source, TreeMap<Key,Valu
TreeMap<Key,Value> seen = new TreeMap<>();

while (iter.hasTop()) {
assertFalse("already contains " + iter.getTopKey(), seen.containsKey(iter.getTopKey()));
assertFalse(seen.containsKey(iter.getTopKey()), "already contains " + iter.getTopKey());
seen.put(new Key(iter.getTopKey()), new Value(iter.getTopValue()));

if (reseek)

0 comments on commit bf88eb1

Please sign in to comment.