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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml: Akka 2.6 features #2517

Merged
merged 1 commit into from
Nov 5, 2020
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ lazy val udp = alpakkaProject("udp", "udp")

lazy val unixdomainsocket = alpakkaProject("unix-domain-socket", "unixdomainsocket", Dependencies.UnixDomainSocket)

lazy val xml = alpakkaProject("xml", "xml", Dependencies.Xml)
lazy val xml = alpakkaProject("xml", "xml", Dependencies.Xml, fatalWarnings := true)

lazy val docs = project
.enablePlugins(AkkaParadoxPlugin, ParadoxSitePlugin, PreprocessPlugin, PublishRsyncPlugin)
Expand Down
22 changes: 7 additions & 15 deletions xml/src/test/java/docs/javadsl/XmlParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package docs.javadsl;

import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import akka.stream.Materializer;
import akka.stream.alpakka.testkit.javadsl.LogCapturingJunit4;
import akka.stream.alpakka.xml.Characters;
import akka.stream.alpakka.xml.EndDocument;
Expand Down Expand Up @@ -44,7 +42,6 @@ public class XmlParsingTest {
@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

private static ActorSystem system;
private static Materializer materializer;

@Test
public void xmlParser() throws InterruptedException, ExecutionException, TimeoutException {
Expand All @@ -59,8 +56,7 @@ public void xmlParser() throws InterruptedException, ExecutionException, Timeout

// #parser-usage
final String doc = "<doc><elem>elem1</elem><elem>elem2</elem></doc>";
final CompletionStage<List<ParseEvent>> resultStage =
Source.single(doc).runWith(parse, materializer);
final CompletionStage<List<ParseEvent>> resultStage = Source.single(doc).runWith(parse, system);
// #parser-usage

resultStage
Expand Down Expand Up @@ -120,7 +116,7 @@ public void parseAndReadEvents() throws Exception {
}
};
})
.runWith(Sink.seq(), materializer);
.runWith(Sink.seq(), system);

List<String> list = stage.toCompletableFuture().get(5, TimeUnit.SECONDS);
assertThat(list, hasItems("elem1", "elem2"));
Expand All @@ -139,8 +135,7 @@ public void xmlParserConfigured()
.toMat(Sink.seq(), Keep.right());

final String doc = "<doc><elem>elem1</elem><elem>elem2</elem></doc>";
final CompletionStage<List<ParseEvent>> resultStage =
Source.single(doc).runWith(parse, materializer);
final CompletionStage<List<ParseEvent>> resultStage = Source.single(doc).runWith(parse, system);

resultStage
.thenAccept(
Expand Down Expand Up @@ -185,8 +180,7 @@ public void xmlSubslice() throws InterruptedException, ExecutionException, Timeo
+ " <item>i3</item>"
+ " </elem>"
+ "</doc>";
final CompletionStage<List<ParseEvent>> resultStage =
Source.single(doc).runWith(parse, materializer);
final CompletionStage<List<ParseEvent>> resultStage = Source.single(doc).runWith(parse, system);
// #subslice-usage

resultStage
Expand Down Expand Up @@ -226,8 +220,7 @@ public void xmlSubtree() throws InterruptedException, ExecutionException, Timeou
+ " <item>i3</item>"
+ " </elem>"
+ "</doc>";
final CompletionStage<List<Element>> resultStage =
Source.single(doc).runWith(parse, materializer);
final CompletionStage<List<Element>> resultStage = Source.single(doc).runWith(parse, system);
// #subtree-usage

resultStage
Expand All @@ -242,13 +235,12 @@ public void xmlSubtree() throws InterruptedException, ExecutionException, Timeou
}

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
system = ActorSystem.create();
materializer = ActorMaterializer.create(system);
}

@AfterClass
public static void teardown() throws Exception {
public static void teardown() {
TestKit.shutdownActorSystem(system);
}
}
14 changes: 5 additions & 9 deletions xml/src/test/java/docs/javadsl/XmlWritingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package docs.javadsl;

import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import akka.stream.Materializer;
import akka.stream.alpakka.testkit.javadsl.LogCapturingJunit4;
import akka.stream.alpakka.xml.*;
import akka.stream.alpakka.xml.javadsl.XmlWriting;
Expand Down Expand Up @@ -38,7 +36,6 @@ public class XmlWritingTest {
@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4();

private static ActorSystem system;
private static Materializer materializer;

@Test
public void xmlWriter() throws InterruptedException, ExecutionException, TimeoutException {
Expand All @@ -65,7 +62,7 @@ public void xmlWriter() throws InterruptedException, ExecutionException, Timeout
docList.add(EndElement.create("doc"));
docList.add(EndDocument.getInstance());

final CompletionStage<String> resultStage = Source.from(docList).runWith(write, materializer);
final CompletionStage<String> resultStage = Source.from(docList).runWith(write, system);

resultStage
.thenAccept((str) -> assertEquals(doc, str))
Expand Down Expand Up @@ -118,7 +115,7 @@ public void xmlWriterNamespace()
docList.add(EndElement.create("book"));
docList.add(EndDocument.getInstance());

final CompletionStage<String> resultStage = Source.from(docList).runWith(write, materializer);
final CompletionStage<String> resultStage = Source.from(docList).runWith(write, system);
// #writer-usage

resultStage
Expand Down Expand Up @@ -154,7 +151,7 @@ public void xmlWriterProvidedFactory()
docList.add(EndElement.create("doc"));
docList.add(EndDocument.getInstance());

final CompletionStage<String> resultStage = Source.from(docList).runWith(write, materializer);
final CompletionStage<String> resultStage = Source.from(docList).runWith(write, system);

resultStage
.thenAccept((str) -> assertEquals(doc, str))
Expand All @@ -163,13 +160,12 @@ public void xmlWriterProvidedFactory()
}

@BeforeClass
public static void setup() throws Exception {
public static void setup() {
system = ActorSystem.create();
materializer = ActorMaterializer.create(system);
}

@AfterClass
public static void teardown() throws Exception {
public static void teardown() {
TestKit.shutdownActorSystem(system);
}
}
2 changes: 0 additions & 2 deletions xml/src/test/scala/docs/scaladsl/XmlCoalesceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docs.scaladsl

import akka.actor.ActorSystem
import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.stream.{ActorMaterializer, Materializer}
import akka.stream.alpakka.xml._
import akka.stream.alpakka.xml.scaladsl.XmlParsing
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
Expand All @@ -20,7 +19,6 @@ import org.scalatest.wordspec.AnyWordSpec

class XmlCoalesceSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll with LogCapturing {
implicit val system: ActorSystem = ActorSystem("Test")
implicit val mat: Materializer = ActorMaterializer()

val parse = Flow[String]
.map(ByteString(_))
Expand Down
2 changes: 0 additions & 2 deletions xml/src/test/scala/docs/scaladsl/XmlProcessingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.stream.alpakka.xml._
import akka.stream.alpakka.xml.scaladsl.XmlParsing
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
import akka.stream.{ActorMaterializer, Materializer}
import akka.util.ByteString
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.BeforeAndAfterAll
Expand All @@ -22,7 +21,6 @@ import org.scalatest.wordspec.AnyWordSpec

class XmlProcessingSpec extends AnyWordSpec with Matchers with ScalaFutures with BeforeAndAfterAll with LogCapturing {
implicit val system: ActorSystem = ActorSystem("Test")
implicit val mat: Materializer = ActorMaterializer()
implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 2.seconds, interval = 50.millis)

// #parser
Expand Down
2 changes: 0 additions & 2 deletions xml/src/test/scala/docs/scaladsl/XmlSubsliceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docs.scaladsl

import akka.actor.ActorSystem
import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.stream.{ActorMaterializer, Materializer}
import akka.stream.alpakka.xml._
import akka.stream.alpakka.xml.scaladsl.XmlParsing
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
Expand All @@ -20,7 +19,6 @@ import org.scalatest.wordspec.AnyWordSpec

class XmlSubsliceSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll with LogCapturing {
implicit val system: ActorSystem = ActorSystem("Test")
implicit val mat: Materializer = ActorMaterializer()

//#subslice
val parse = Flow[String]
Expand Down
2 changes: 0 additions & 2 deletions xml/src/test/scala/docs/scaladsl/XmlSubtreeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docs.scaladsl

import akka.actor.ActorSystem
import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.stream.{ActorMaterializer, Materializer}
import akka.stream.alpakka.xml.scaladsl.XmlParsing
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
import akka.util.ByteString
Expand All @@ -20,7 +19,6 @@ import org.scalatest.wordspec.AnyWordSpec

class XmlSubtreeSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll with LogCapturing {
implicit val system: ActorSystem = ActorSystem("Test")
implicit val mat: Materializer = ActorMaterializer()

//#subtree
val parse = Flow[String]
Expand Down
2 changes: 0 additions & 2 deletions xml/src/test/scala/docs/scaladsl/XmlWritingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package docs.scaladsl

import akka.actor.ActorSystem
import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.stream.{ActorMaterializer, Materializer}
import akka.stream.alpakka.xml._
import akka.stream.alpakka.xml.scaladsl.XmlWriting
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
Expand All @@ -22,7 +21,6 @@ import org.scalatest.wordspec.AnyWordSpec

class XmlWritingSpec extends AnyWordSpec with Matchers with BeforeAndAfterAll with ScalaFutures with LogCapturing {
implicit val system: ActorSystem = ActorSystem("Test")
implicit val mat: Materializer = ActorMaterializer()

// #writer
val writer: Sink[ParseEvent, Future[String]] = Flow[ParseEvent]
Expand Down