Make warnings in Java code fatal (#28402)
This commit is contained in:
parent
58fa1e3604
commit
327e16980d
51 changed files with 480 additions and 213 deletions
|
|
@ -524,14 +524,17 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
// #creating-props-deprecated
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
// Commented out because this 'Props.create' overload is now deprecated
|
||||
// @Test(expected = IllegalArgumentException.class)
|
||||
public void creatingPropsIllegal() {
|
||||
/*
|
||||
// #creating-props-illegal
|
||||
// This will throw an IllegalArgumentException since some runtime
|
||||
// type information of the lambda is erased.
|
||||
// Use Props.create(actorClass, Creator) instead.
|
||||
Props props = Props.create(() -> new ActorWithArgs("arg"));
|
||||
// #creating-props-illegal
|
||||
*/
|
||||
}
|
||||
|
||||
public
|
||||
|
|
|
|||
|
|
@ -24,14 +24,27 @@ public class DnsCompileOnlyDocTest {
|
|||
final Duration timeout = Duration.ofMillis(1000L);
|
||||
|
||||
// #resolve
|
||||
Option<Dns.Resolved> initial = Dns.get(system).cache().resolve("google.com", system, actorRef);
|
||||
Option<Dns.Resolved> cached = Dns.get(system).cache().cached("google.com");
|
||||
Option<DnsProtocol.Resolved> initial =
|
||||
Dns.get(system)
|
||||
.cache()
|
||||
.resolve(
|
||||
new DnsProtocol.Resolve("google.com", DnsProtocol.ipRequestType()),
|
||||
system,
|
||||
actorRef);
|
||||
Option<DnsProtocol.Resolved> cached =
|
||||
Dns.get(system)
|
||||
.cache()
|
||||
.cached(new DnsProtocol.Resolve("google.com", DnsProtocol.ipRequestType()));
|
||||
// #resolve
|
||||
|
||||
{
|
||||
// #actor-api-inet-address
|
||||
final ActorRef dnsManager = Dns.get(system).manager();
|
||||
CompletionStage<Object> resolved = ask(dnsManager, new Dns.Resolve("google.com"), timeout);
|
||||
CompletionStage<Object> resolved =
|
||||
ask(
|
||||
dnsManager,
|
||||
new DnsProtocol.Resolve("google.com", DnsProtocol.ipRequestType()),
|
||||
timeout);
|
||||
// #actor-api-inet-address
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import akka.cluster.ddata.Replicator.Changed;
|
|||
import akka.cluster.ddata.Replicator.Subscribe;
|
||||
import akka.cluster.ddata.Replicator.Update;
|
||||
import akka.cluster.ddata.Replicator.UpdateResponse;
|
||||
import akka.cluster.ddata.SelfUniqueAddress;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
|
||||
|
|
@ -31,7 +32,8 @@ public class DataBot extends AbstractActor {
|
|||
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
private final ActorRef replicator = DistributedData.get(getContext().getSystem()).replicator();
|
||||
private final Cluster node = Cluster.get(getContext().getSystem());
|
||||
private final SelfUniqueAddress node =
|
||||
DistributedData.get(getContext().getSystem()).selfUniqueAddress();
|
||||
|
||||
private final Cancellable tickTask =
|
||||
getContext()
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
static
|
||||
// #update-request-context
|
||||
class DemonstrateUpdateWithRequestContext extends AbstractActor {
|
||||
final Cluster node = Cluster.get(getContext().getSystem());
|
||||
final SelfUniqueAddress node = DistributedData.get(system).selfUniqueAddress();
|
||||
final ActorRef replicator = DistributedData.get(getContext().getSystem()).replicator();
|
||||
|
||||
final WriteConsistency writeTwo = new WriteTo(2, Duration.ofSeconds(3));
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class MyEventsByTagSource extends GraphStage<SourceShape<EventEnvelope>>
|
|||
|
||||
@Override
|
||||
public void preStart() {
|
||||
schedulePeriodically(Continue.INSTANCE, refreshInterval);
|
||||
scheduleWithFixedDelay(Continue.INSTANCE, refreshInterval, refreshInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -109,7 +109,8 @@ public class MyEventsByTagSource extends GraphStage<SourceShape<EventEnvelope>>
|
|||
Offset.sequence(currentOffset),
|
||||
rs.getString("persistence_id"),
|
||||
rs.getLong("seq_nr"),
|
||||
deserialized));
|
||||
deserialized,
|
||||
System.currentTimeMillis()));
|
||||
}
|
||||
buf = res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]));
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue