Skip to content

Commit

Permalink
use testng to replace junit (apache#11033)
Browse files Browse the repository at this point in the history
### Motivation
Pulsar uses TestNG, but some tests are still using junit

### Modifications
Use testng instead of junit
  • Loading branch information
hangc0276 authored Jul 14, 2021
1 parent 6384f94 commit 70e9c48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public final class TestEnvVarResolverProperties {
private PropertiesFileConfigurationProvider provider;

@Before
public void setUp() throws Exception {
public void setUp() {
provider = new PropertiesFileConfigurationProvider("a1", TESTFILE);
}

@Test
public void resolveEnvVar() throws Exception {
public void resolveEnvVar() {
environmentVariables.set("VARNAME", "varvalue");
String resolved = EnvVarResolverProperties.resolveEnvVars("padding ${VARNAME} padding");
Assert.assertEquals("padding varvalue padding", resolved);
}

@Test
public void resolveEnvVars() throws Exception {
public void resolveEnvVars() {
environmentVariables.set("VARNAME1", "varvalue1");
environmentVariables.set("VARNAME2", "varvalue2");
String resolved = EnvVarResolverProperties
Expand All @@ -56,7 +56,7 @@ public void resolveEnvVars() throws Exception {
}

@Test
public void getProperty() throws Exception {
public void getProperty() {
String NC_PORT = "6667";
environmentVariables.set("NC_PORT", NC_PORT);
System.setProperty("propertiesImplementation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.fail;

@SuppressWarnings({"unchecked", "rawtypes"})
@Slf4j
Expand Down Expand Up @@ -138,12 +138,12 @@ public void smokeTest() throws Exception {
sink.write(record);
sink.flush();

assertEquals(1, status.get());
assertEquals(status.get(), 1);

sink.close();

List<String> lines = Files.readAllLines(file, StandardCharsets.US_ASCII);
assertEquals("value", lines.get(0));
assertEquals(lines.get(0), "value");
}

@Test
Expand All @@ -169,15 +169,15 @@ public void seekPauseResumeTest() throws Exception {
sink.write(record);
sink.flush();

assertEquals(1, status.get());
assertEquals(status.get(), 1);

final TopicPartition tp = new TopicPartition("fake-topic", 0);
assertNotEquals(0, MessageIdUtils.getOffset(msgId));
assertEquals(MessageIdUtils.getOffset(msgId), sink.currentOffset(tp.topic(), tp.partition()));
assertNotEquals(MessageIdUtils.getOffset(msgId), 0);
assertEquals(sink.currentOffset(tp.topic(), tp.partition()), MessageIdUtils.getOffset(msgId));

sink.taskContext.offset(tp, 0);
verify(context, times(1)).seek(Mockito.anyString(), Mockito.anyInt(), any());
assertEquals(0, sink.currentOffset(tp.topic(), tp.partition()));
assertEquals(sink.currentOffset(tp.topic(), tp.partition()), 0);

sink.taskContext.pause(tp);
verify(context, times(1)).pause(tp.topic(), tp.partition());
Expand Down Expand Up @@ -260,18 +260,18 @@ private void recordSchemaTest(Object value, Schema schema, Object expectedKey, S
sink.write(record);
sink.flush();

assertEquals(1, status.get());
assertEquals(status.get(), 1);

sink.close();

List<String> lines = Files.readAllLines(file, StandardCharsets.US_ASCII);
ObjectMapper om = new ObjectMapper();
Map<String, Object> result = om.readValue(lines.get(0), new TypeReference<Map<String, Object>>(){});

assertEquals(expectedKey, result.get("key"));
assertEquals(expected, result.get("value"));
assertEquals(expectedKeySchema, result.get("keySchema"));
assertEquals(expectedSchema, result.get("valueSchema"));
assertEquals(result.get("key"), expectedKey);
assertEquals(result.get("value"), expected);
assertEquals(result.get("keySchema"), expectedKeySchema);
assertEquals(result.get("valueSchema"), expectedSchema);
}

private GenericRecord getGenericRecord(Object value, Schema schema) {
Expand Down Expand Up @@ -382,7 +382,7 @@ public void unknownRecordSchemaTest() throws Exception {
sink.write(record);
sink.flush();

assertEquals("write should fail for unsupported schema",-1, status.get());
assertEquals(status.get(), -1, "write should fail for unsupported schema");

sink.close();
}
Expand Down Expand Up @@ -418,18 +418,18 @@ public void offsetTest() throws Exception {
sink.open(props, context);

// offset is -1 before any data is written (aka no offset)
assertEquals(-1L, sink.currentOffset(topicName, partition));
assertEquals(sink.currentOffset(topicName, partition), -1L);

sink.write(record);
sink.flush();

// offset is 0 for the first written record
assertEquals(0, sink.currentOffset(topicName, partition));
assertEquals(sink.currentOffset(topicName, partition), 0);

sink.write(record);
sink.flush();
// offset is 1 for the second written record
assertEquals(1, sink.currentOffset(topicName, partition));
assertEquals(sink.currentOffset(topicName, partition), 1);

sink.close();

Expand All @@ -441,12 +441,12 @@ public void offsetTest() throws Exception {
sink.open(props, context);

// offset is 1 after reopening the producer
assertEquals(1, sink.currentOffset(topicName, partition));
assertEquals(sink.currentOffset(topicName, partition), 1);

sink.write(record);
sink.flush();
// offset is 2 for the next written record
assertEquals(2, sink.currentOffset(topicName, partition));
assertEquals(sink.currentOffset(topicName, partition), 2);

sink.close();
}
Expand Down

0 comments on commit 70e9c48

Please sign in to comment.