Make warnings in Java code fatal (#28402)

This commit is contained in:
Arnout Engelen 2020-08-04 13:47:38 +02:00 committed by GitHub
parent 58fa1e3604
commit 327e16980d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 480 additions and 213 deletions

View file

@ -4,6 +4,7 @@
package jdocs.stream;
import akka.Done;
import akka.NotUsed;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
@ -157,7 +158,7 @@ public class FlowDocTest extends AbstractJavaTest {
Source.from(list);
// Create a source form a Future
Source.fromFuture(Futures.successful("Hello Streams!"));
Source.future(Futures.successful("Hello Streams!"));
// Create a source from a single element
Source.single("only one element");
@ -274,7 +275,17 @@ public class FlowDocTest extends AbstractJavaTest {
@Test
public void sourcePreMaterialization() {
// #source-prematerialization
Source<String, ActorRef> matValuePoweredSource = Source.actorRef(100, OverflowStrategy.fail());
Source<String, ActorRef> matValuePoweredSource =
Source.actorRef(
elem -> {
// complete stream immediately if we send it Done
if (elem == Done.done()) return Optional.of(CompletionStrategy.immediately());
else return Optional.empty();
},
// never fail the stream because of a message
elem -> Optional.empty(),
100,
OverflowStrategy.fail());
Pair<ActorRef, Source<String, NotUsed>> actorRefSourcePair =
matValuePoweredSource.preMaterialize(system);

View file

@ -179,7 +179,9 @@ public class FlowErrorDocTest extends AbstractJavaTest {
})
.recoverWithRetries(
1, // max attempts
new PFBuilder().match(RuntimeException.class, ex -> planB).build())
new PFBuilder<Throwable, Source<String, NotUsed>>()
.match(RuntimeException.class, ex -> planB)
.build())
.runForeach(System.out::println, system);
// #recoverWithRetries

View file

@ -221,7 +221,7 @@ public class GraphStageDocTest extends AbstractJavaTest {
.via(stringLength)
.runFold(0, (sum, n) -> sum + n, system);
assertEquals(new Integer(11), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(11), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
}
// #many-to-one
@ -286,7 +286,7 @@ public class GraphStageDocTest extends AbstractJavaTest {
.via(evenFilter)
.runFold(0, (elem, sum) -> sum + elem, system);
assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
}
// #one-to-many
@ -356,7 +356,7 @@ public class GraphStageDocTest extends AbstractJavaTest {
CompletionStage<Integer> result =
Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, system);
assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
}
// #simpler-one-to-many
@ -412,7 +412,7 @@ public class GraphStageDocTest extends AbstractJavaTest {
CompletionStage<Integer> result =
Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, system);
assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
}
@Test
@ -588,7 +588,7 @@ public class GraphStageDocTest extends AbstractJavaTest {
.takeWithin(java.time.Duration.ofMillis(250))
.runFold(0, (n, sum) -> n + sum, system);
assertEquals(new Integer(1), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(1), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
}
// #materialized
@ -654,12 +654,12 @@ public class GraphStageDocTest extends AbstractJavaTest {
// tests:
RunnableGraph<CompletionStage<Integer>> flow =
Source.from(Arrays.asList(1, 2, 3))
.viaMat(new FirstValue(), Keep.right())
.viaMat(new FirstValue<Integer>(), Keep.right())
.to(Sink.ignore());
CompletionStage<Integer> result = flow.run(system);
assertEquals(new Integer(1), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(1), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
}
// #detached
@ -751,7 +751,7 @@ public class GraphStageDocTest extends AbstractJavaTest {
.via(new TwoBuffer<>())
.runFold(0, (acc, n) -> acc + n, system);
assertEquals(new Integer(6), result1.toCompletableFuture().get(3, TimeUnit.SECONDS));
assertEquals(Integer.valueOf(6), result1.toCompletableFuture().get(3, TimeUnit.SECONDS));
TestSubscriber.ManualProbe<Integer> subscriber = TestSubscriber.manualProbe(system);
TestPublisher.Probe<Integer> publisher = TestPublisher.probe(0, system);

View file

@ -4,6 +4,7 @@
package jdocs.stream;
import akka.Done;
import akka.NotUsed;
import akka.actor.*;
import akka.stream.*;
@ -773,7 +774,15 @@ public class IntegrationDocTest extends AbstractJavaTest {
Source<Integer, ActorRef> source =
Source.actorRef(
bufferSize, OverflowStrategy.dropHead()); // note: backpressure is not supported
elem -> {
// complete stream immediately if we send it Done
if (elem == Done.done()) return Optional.of(CompletionStrategy.immediately());
else return Optional.empty();
},
// never fail the stream because of a message
elem -> Optional.empty(),
bufferSize,
OverflowStrategy.dropHead()); // note: backpressure is not supported
ActorRef actorRef =
source
.map(x -> x * x)

View file

@ -69,7 +69,7 @@ public class RestartDocTest {
20, // limits the amount of restarts to 20
() ->
// Create a source from a future of a source
Source.fromSourceCompletionStage(
Source.completionStageSource(
// Issue a GET request on the event stream
Http.get(system)
.singleRequest(HttpRequest.create("http://example.com/eventstream"))

View file

@ -54,8 +54,8 @@ public class StreamPartialGraphDSLDocTest extends AbstractJavaTest {
builder.from(zip1.out()).toInlet(zip2.in0());
// return the shape, which has three inputs and one output
return new UniformFanInShape<Integer, Integer>(
zip2.out(), new Inlet[] {zip1.in0(), zip1.in1(), zip2.in1()});
return UniformFanInShape.<Integer, Integer>create(
zip2.out(), Arrays.asList(zip1.in0(), zip1.in1(), zip2.in1()));
});
final Sink<Integer, CompletionStage<Integer>> resultSink = Sink.<Integer>head();

View file

@ -8,11 +8,13 @@ import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import akka.Done;
import akka.NotUsed;
import jdocs.AbstractJavaTest;
import akka.testkit.javadsl.TestKit;
@ -128,7 +130,16 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
.toMat(Sink.fold("", (agg, next) -> agg + next), Keep.right());
final Pair<ActorRef, CompletionStage<String>> refAndCompletionStage =
Source.<Integer>actorRef(8, OverflowStrategy.fail())
Source.<Integer>actorRef(
elem -> {
// complete stream immediately if we send it Done
if (elem == Done.done()) return Optional.of(CompletionStrategy.immediately());
else return Optional.empty();
},
// never fail the stream because of a message
elem -> Optional.empty(),
8,
OverflowStrategy.fail())
.toMat(sinkUnderTest, Keep.both())
.run(system);
final ActorRef ref = refAndCompletionStage.first();
@ -137,7 +148,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
ref.tell(1, ActorRef.noSender());
ref.tell(2, ActorRef.noSender());
ref.tell(3, ActorRef.noSender());
ref.tell(new akka.actor.Status.Success("done"), ActorRef.noSender());
ref.tell(Done.getInstance(), ActorRef.noSender());
final String result = future.toCompletableFuture().get(1, TimeUnit.SECONDS);
assertEquals(result, "123");

View file

@ -5,6 +5,7 @@
package jdocs.stream.javadsl.cookbook;
import akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.dispatch.Futures;
import akka.japi.pf.PFBuilder;
@ -45,16 +46,18 @@ public class RecipeAdhocSourceTest extends RecipeTest {
// #adhoc-source
public <T> Source<T, ?> adhocSource(Source<T, ?> source, Duration timeout, int maxRetries) {
return Source.lazily(
return Source.lazySource(
() ->
source
.backpressureTimeout(timeout)
.recoverWithRetries(
maxRetries,
new PFBuilder()
new PFBuilder<Throwable, Source<T, NotUsed>>()
.match(
TimeoutException.class,
ex -> Source.lazily(() -> source.backpressureTimeout(timeout)))
ex ->
Source.lazySource(() -> source.backpressureTimeout(timeout))
.mapMaterializedValue(v -> NotUsed.getInstance()))
.build()));
}
// #adhoc-source

View file

@ -30,7 +30,7 @@ public class StatefulMapConcat {
return (element) -> {
counter[0] += 1;
// we return an iterable with the single element
return Arrays.asList(new Pair(element, counter[0]));
return Arrays.asList(new Pair<String, Long>(element, counter[0]));
};
});