Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions amqp/src/test/java/docs/javadsl/AmqpDocsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import org.apache.pekko.stream.connectors.amqp.javadsl.AmqpSink;
import org.apache.pekko.stream.connectors.amqp.javadsl.AmqpSource;
import org.apache.pekko.stream.connectors.amqp.javadsl.CommittableReadResult;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingJunit4;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingExtension;
import org.junit.jupiter.api.extension.ExtendWith;
import org.apache.pekko.stream.javadsl.Flow;
import org.apache.pekko.stream.javadsl.Keep;
import org.apache.pekko.stream.javadsl.Sink;
Expand All @@ -37,34 +38,33 @@
import org.apache.pekko.testkit.javadsl.TestKit;
import org.apache.pekko.util.ByteString;

import org.junit.*;
import org.junit.jupiter.api.*;

import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;

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

/** Needs a local running AMQP server on the default port with no password. */
@ExtendWith(LogCapturingExtension.class)
public class AmqpDocsTest {

@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

private static ActorSystem system;

@BeforeClass
@BeforeAll
public static void setup() {
system = ActorSystem.create();
}

@AfterClass
@AfterAll
public static void teardown() {
TestKit.shutdownActorSystem(system);
}

@After
@AfterEach
public void checkForStageLeaks() {
StreamTestKit.assertAllStagesStopped(Materializer.matFromSystem(system));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
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 org.apache.pekko.stream.connectors.amqp.*;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingJunit4;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingExtension;
import org.junit.jupiter.api.extension.ExtendWith;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.junit.Rule;
import org.junit.Test;

import org.junit.jupiter.api.Test;

import java.net.ConnectException;

@ExtendWith(LogCapturingExtension.class)
public class AmqpConnectionProvidersTest {

@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

@Test
public void LocalAmqpConnectionCreatesNewConnection() throws Exception {
AmqpConnectionProvider connectionProvider = AmqpLocalConnectionProvider.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import org.apache.pekko.stream.Materializer;
import org.apache.pekko.stream.UniqueKillSwitch;
import org.apache.pekko.stream.connectors.amqp.*;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingJunit4;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingExtension;
import org.junit.jupiter.api.extension.ExtendWith;
import org.apache.pekko.stream.javadsl.Flow;
import org.apache.pekko.stream.javadsl.Keep;
import org.apache.pekko.stream.javadsl.Sink;
Expand All @@ -32,7 +33,7 @@
import org.apache.pekko.testkit.javadsl.TestKit;
import org.apache.pekko.util.ByteString;
import com.rabbitmq.client.AuthenticationFailureException;
import org.junit.*;
import org.junit.jupiter.api.*;
import scala.collection.JavaConverters;
import scala.concurrent.duration.Duration;

Expand All @@ -42,35 +43,34 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

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

/** Needs a local running AMQP server on the default port with no password. */
@ExtendWith(LogCapturingExtension.class)
public class AmqpConnectorsTest {

@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

private static ActorSystem system;

@BeforeClass
@BeforeAll
public static void setup() {
system = ActorSystem.create();
}

@AfterClass
@AfterAll
public static void teardown() {
TestKit.shutdownActorSystem(system);
}

@After
@AfterEach
public void checkForStageLeaks() {
StreamTestKit.assertAllStagesStopped(Materializer.matFromSystem(system));
}

private AmqpConnectionProvider connectionProvider = AmqpLocalConnectionProvider.getInstance();

@Test(expected = ConnectException.class)
public void throwIfCanNotConnect() throws Throwable {
@Test
public void throwIfCanNotConnect() {
final String queueName = "amqp-conn-it-spec-simple-queue-" + System.currentTimeMillis();
final QueueDeclaration queueDeclaration = QueueDeclaration.create(queueName);

Expand All @@ -88,15 +88,19 @@ public void throwIfCanNotConnect() throws Throwable {
final CompletionStage<Done> result =
Source.from(input).map(ByteString::fromString).runWith(amqpSink, system);

try {
result.toCompletableFuture().get();
} catch (ExecutionException e) {
throw e.getCause();
}
Assertions.assertThrows(
ConnectException.class,
() -> {
try {
result.toCompletableFuture().get();
} catch (ExecutionException e) {
throw e.getCause();
}
});
}

@Test(expected = AuthenticationFailureException.class)
public void throwWithWrongCredentials() throws Throwable {
@Test
public void throwWithWrongCredentials() {
final String queueName = "amqp-conn-it-spec-simple-queue-" + System.currentTimeMillis();
final QueueDeclaration queueDeclaration = QueueDeclaration.create(queueName);

Expand All @@ -116,11 +120,15 @@ public void throwWithWrongCredentials() throws Throwable {
final CompletionStage<Done> result =
Source.from(input).map(ByteString::fromString).runWith(amqpSink, system);

try {
result.toCompletableFuture().get();
} catch (ExecutionException e) {
throw e.getCause();
}
Assertions.assertThrows(
AuthenticationFailureException.class,
() -> {
try {
result.toCompletableFuture().get();
} catch (ExecutionException e) {
throw e.getCause();
}
});
// assertEquals(input, result.toCompletableFuture().get(3, TimeUnit.SECONDS).stream().map(m ->
// m.bytes().utf8String()).toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@

import scala.collection.JavaConverters;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeAll;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import org.apache.pekko.Done;
import org.apache.pekko.actor.ActorSystem;
Expand All @@ -35,7 +32,8 @@
import org.apache.pekko.stream.connectors.amqp.QueueDeclaration;
import org.apache.pekko.stream.connectors.amqp.WriteMessage;
import org.apache.pekko.stream.connectors.amqp.WriteResult;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingJunit4;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingExtension;
import org.junit.jupiter.api.extension.ExtendWith;
import org.apache.pekko.stream.javadsl.Flow;
import org.apache.pekko.stream.javadsl.FlowWithContext;
import org.apache.pekko.stream.javadsl.Keep;
Expand All @@ -45,27 +43,17 @@
import org.apache.pekko.util.ByteString;

/** Needs a local running AMQP server on the default port with no password. */
@RunWith(Parameterized.class)
@ExtendWith(LogCapturingExtension.class)
public class AmqpFlowTest {

@Parameters
public static Iterable<? extends Object> data() {
return List.of(false, true);
}

/** This value is initialized with values from data() array */
@Parameter public boolean reuseByteArray;

@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

private static ActorSystem system;

@BeforeClass
@BeforeAll
public static void setup() {
system = ActorSystem.create();
}

private AmqpWriteSettings settings() {
private AmqpWriteSettings settings(boolean reuseByteArray) {
final String queueName = "amqp-flow-spec" + System.currentTimeMillis();
final QueueDeclaration queueDeclaration = QueueDeclaration.create(queueName);

Expand All @@ -77,19 +65,25 @@ private AmqpWriteSettings settings() {
.withConfirmationTimeout(Duration.ofMillis(200));
}

@Test
public void shouldEmitConfirmationForPublishedMessagesInSimpleFlow() {
shouldEmitConfirmationForPublishedMessages(AmqpFlow.create(settings()));
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void shouldEmitConfirmationForPublishedMessagesInSimpleFlow(boolean reuseByteArray) {
shouldEmitConfirmationForPublishedMessages(AmqpFlow.create(settings(reuseByteArray)));
}

@Test
public void shouldEmitConfirmationForPublishedMessagesInFlowWithConfirm() {
shouldEmitConfirmationForPublishedMessages(AmqpFlow.createWithConfirm(settings()));
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void shouldEmitConfirmationForPublishedMessagesInFlowWithConfirm(boolean reuseByteArray) {
shouldEmitConfirmationForPublishedMessages(
AmqpFlow.createWithConfirm(settings(reuseByteArray)));
}

@Test
public void shouldEmitConfirmationForPublishedMessagesInFlowWithConfirmUnordered() {
shouldEmitConfirmationForPublishedMessages(AmqpFlow.createWithConfirmUnordered(settings()));
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void shouldEmitConfirmationForPublishedMessagesInFlowWithConfirmUnordered(
boolean reuseByteArray) {
shouldEmitConfirmationForPublishedMessages(
AmqpFlow.createWithConfirmUnordered(settings(reuseByteArray)));
}

private void shouldEmitConfirmationForPublishedMessages(
Expand All @@ -111,14 +105,16 @@ private void shouldEmitConfirmationForPublishedMessages(
.expectNextN(JavaConverters.asScalaBufferConverter(expectedOutput).asScala().toList());
}

@Test
public void shouldPropagateContextInSimpleFlow() {
shouldPropagateContext(AmqpFlowWithContext.create(settings()));
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void shouldPropagateContextInSimpleFlow(boolean reuseByteArray) {
shouldPropagateContext(AmqpFlowWithContext.create(settings(reuseByteArray)));
}

@Test
public void shouldPropagateContextInFlowWithConfirm() {
shouldPropagateContext(AmqpFlowWithContext.createWithConfirm(settings()));
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void shouldPropagateContextInFlowWithConfirm(boolean reuseByteArray) {
shouldPropagateContext(AmqpFlowWithContext.createWithConfirm(settings(reuseByteArray)));
}

private void shouldPropagateContext(
Expand All @@ -143,10 +139,11 @@ private void shouldPropagateContext(
.expectNextN(JavaConverters.asScalaBufferConverter(expectedOutput).asScala().toList());
}

@Test
public void shouldPropagatePassThrough() {
@ParameterizedTest
@ValueSource(booleans = {false, true})
public void shouldPropagatePassThrough(boolean reuseByteArray) {
Flow<Pair<WriteMessage, String>, Pair<WriteResult, String>, CompletionStage<Done>> flow =
AmqpFlow.createWithConfirmAndPassThroughUnordered(settings());
AmqpFlow.createWithConfirmAndPassThroughUnordered(settings(reuseByteArray));

final List<String> input = List.of("one", "two", "three", "four", "five");
final List<Pair<WriteResult, String>> expectedOutput =
Expand Down
20 changes: 10 additions & 10 deletions avroparquet/src/test/java/docs/javadsl/AvroParquetSinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.stream.Materializer;
import org.apache.pekko.stream.connectors.avroparquet.javadsl.AvroParquetSink;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingJunit4;
import org.apache.pekko.stream.connectors.testkit.javadsl.LogCapturingExtension;
import org.junit.jupiter.api.extension.ExtendWith;
import org.apache.pekko.stream.javadsl.Sink;
import org.apache.pekko.stream.javadsl.Source;
import org.apache.pekko.stream.testkit.javadsl.StreamTestKit;
Expand All @@ -28,10 +29,10 @@
import org.apache.parquet.avro.AvroReadSupport;
import org.apache.parquet.hadoop.ParquetFileWriter;
import org.apache.parquet.hadoop.ParquetReader;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -41,7 +42,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static junit.framework.TestCase.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

// #init-writer
import org.apache.parquet.hadoop.ParquetWriter;
Expand All @@ -54,10 +55,9 @@

// #init-writer

@ExtendWith(LogCapturingExtension.class)
public class AvroParquetSinkTest {

@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

private final Schema schema =
new Schema.Parser()
.parse(
Expand All @@ -68,7 +68,7 @@ public class AvroParquetSinkTest {
private String folder = "target/javaTestFolder";
private final String file = "./" + folder + "/test.parquet";

@Before
@BeforeEach
public void setup() {
system = ActorSystem.create();
conf.setBoolean(AvroReadSupport.AVRO_COMPATIBILITY, true);
Expand Down Expand Up @@ -122,7 +122,7 @@ private int checkResponse() throws IOException {
return expectedRecords.size();
}

@After
@AfterEach
public void checkForStageLeaksAndDeleteCreatedFiles() {
StreamTestKit.assertAllStagesStopped(Materializer.matFromSystem(system));
TestKit.shutdownActorSystem(system);
Expand Down
Loading