From ae210b17d2a9b2d216918095002f8ba55ec69005 Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Tue, 23 Jan 2024 22:20:01 +0800 Subject: [PATCH] chore: Update java-formatter ignore lists (#1030) * chore: Update java-formatter ignore lists * chore: Reformat JavaFutureTests.java --- .sbt-java-formatter.conf | 32 +- .../pekko/dispatch/JavaFutureTests.java | 286 +++++++++++------- 2 files changed, 201 insertions(+), 117 deletions(-) diff --git a/.sbt-java-formatter.conf b/.sbt-java-formatter.conf index e10f95b2352..eaf139d7c8f 100644 --- a/.sbt-java-formatter.conf +++ b/.sbt-java-formatter.conf @@ -10,7 +10,37 @@ ignored-files = [ "ProtobufProtocol.java" //in docs "TwoPhaseSetMessages.java" - "FlightAppModels.java" + "FlightAppModels.java", + + //pekko-actor + "OnSpinWait.java", + "AbstractBoundedNodeQueue.java", + "AbstractMailbox.java", + "AbstractMessageDispatcher.java", + "AbstractNodeQueue.java", + //pekko-cluster + "ClusterMessages.java", + //pekko-cluster-metrics + "ClusterMetricsMessages.java", + //pekko-cluster-sharding-typed + "ShardingMessages.java", + //pekko-cluster-sharding + "ClusterShardingMessages.java", + //pekko-cluster-tools + "ClusterClientMessages.java", + "DistributedPubSubMessages.java", + //pekko-cluster-typed + "ClusterMessages.java", + "ReliableDelivery.java", + //pekko-distributed-data + "ReplicatedDataMessages.java", + "ReplicatorMessages.java", + //pekko-multi-node-testkit + "TestConductorProtocol.java", + //pekko-persistence + "MessageFormats.java", + //pekko-remote-tests + "TestMessages.java", ] //ignore by packages: diff --git a/actor-tests/src/test/java/org/apache/pekko/dispatch/JavaFutureTests.java b/actor-tests/src/test/java/org/apache/pekko/dispatch/JavaFutureTests.java index ed8b4d5be20..6af8c2b399c 100644 --- a/actor-tests/src/test/java/org/apache/pekko/dispatch/JavaFutureTests.java +++ b/actor-tests/src/test/java/org/apache/pekko/dispatch/JavaFutureTests.java @@ -40,7 +40,7 @@ public class JavaFutureTests extends JUnitSuite { @ClassRule public static PekkoJUnitActorSystemResource actorSystemResource = - new PekkoJUnitActorSystemResource("JavaFutureTests", PekkoSpec.testConf()); + new PekkoJUnitActorSystemResource("JavaFutureTests", PekkoSpec.testConf()); private final ActorSystem system = actorSystemResource.getSystem(); private final Duration timeout = Duration.create(5, TimeUnit.SECONDS); @@ -48,17 +48,23 @@ public class JavaFutureTests extends JUnitSuite { @Test public void mustBeAbleToMapAFuture() throws Exception { - Future f1 = Futures.future(new Callable() { - public String call() { - return "Hello"; - } - }, system.dispatcher()); - - Future f2 = f1.map(new Mapper() { - public String apply(String s) { - return s + " World"; - } - }, system.dispatcher()); + Future f1 = + Futures.future( + new Callable() { + public String call() { + return "Hello"; + } + }, + system.dispatcher()); + + Future f2 = + f1.map( + new Mapper() { + public String apply(String s) { + return s + " World"; + } + }, + system.dispatcher()); assertEquals("Hello World", Await.result(f2, timeout)); } @@ -68,12 +74,13 @@ public void mustBeAbleToExecuteAnOnResultCallback() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(); Future f = cf.future(); - f.onComplete(new OnComplete() { - public void onComplete(Throwable t, String r) { - if ("foo".equals(r)) - latch.countDown(); - } - }, system.dispatcher()); + f.onComplete( + new OnComplete() { + public void onComplete(Throwable t, String r) { + if ("foo".equals(r)) latch.countDown(); + } + }, + system.dispatcher()); cf.success("foo"); assertTrue(latch.await(5, TimeUnit.SECONDS)); @@ -85,13 +92,14 @@ public void mustBeAbleToExecuteAnOnExceptionCallback() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(); Future f = cf.future(); - f.onComplete(new OnComplete() { - public void onComplete(Throwable t, String r) { - // 'null instanceof ...' is always false - if (t instanceof NullPointerException) - latch.countDown(); - } - }, system.dispatcher()); + f.onComplete( + new OnComplete() { + public void onComplete(Throwable t, String r) { + // 'null instanceof ...' is always false + if (t instanceof NullPointerException) latch.countDown(); + } + }, + system.dispatcher()); Throwable exception = new NullPointerException(); cf.failure(exception); @@ -104,11 +112,13 @@ public void mustBeAbleToExecuteAnOnCompleteCallback() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(); Future f = cf.future(); - f.onComplete(new OnComplete() { - public void onComplete(Throwable t, String r) { - latch.countDown(); - } - }, system.dispatcher()); + f.onComplete( + new OnComplete() { + public void onComplete(Throwable t, String r) { + latch.countDown(); + } + }, + system.dispatcher()); cf.success("foo"); assertTrue(latch.await(5, TimeUnit.SECONDS)); @@ -120,11 +130,13 @@ public void mustBeAbleToForeachAFuture() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(); Future f = cf.future(); - f.foreach(new Foreach() { - public void each(String future) { - latch.countDown(); - } - },system.dispatcher()); + f.foreach( + new Foreach() { + public void each(String future) { + latch.countDown(); + } + }, + system.dispatcher()); cf.success("foo"); assertTrue(latch.await(5, TimeUnit.SECONDS)); @@ -137,15 +149,18 @@ public void mustBeAbleToFlatMapAFuture() throws Throwable { Promise cf = Futures.promise(); cf.success("1000"); Future f = cf.future(); - Future r = f.flatMap(new Mapper>() { - public Future checkedApply(String r) throws Throwable { - if (false) throw new IOException("Just here to make sure this compiles."); - latch.countDown(); - Promise cf = Futures.promise(); - cf.success(Integer.parseInt(r)); - return cf.future(); - } - }, system.dispatcher()); + Future r = + f.flatMap( + new Mapper>() { + public Future checkedApply(String r) throws Throwable { + if (false) throw new IOException("Just here to make sure this compiles."); + latch.countDown(); + Promise cf = Futures.promise(); + cf.success(Integer.parseInt(r)); + return cf.future(); + } + }, + system.dispatcher()); assertEquals("1000", Await.result(f, timeout)); assertEquals(1000, Await.result(r, timeout).intValue()); @@ -157,12 +172,16 @@ public void mustBeAbleToFilterAFuture() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); Promise cf = Futures.promise(); Future f = cf.future(); - Future r = f.filter(Filter.filterOf(new Function() { - public Boolean apply(String r) { - latch.countDown(); - return r.equals("foo"); - } - }), system.dispatcher()); + Future r = + f.filter( + Filter.filterOf( + new Function() { + public Boolean apply(String r) { + latch.countDown(); + return r.equals("foo"); + } + }), + system.dispatcher()); cf.success("foo"); assertTrue(latch.await(5, TimeUnit.SECONDS)); @@ -172,17 +191,20 @@ public Boolean apply(String r) { // TODO: Improve this test, perhaps with an Actor @Test - public void mustSequenceAFutureList() throws Exception{ + public void mustSequenceAFutureList() throws Exception { LinkedList> listFutures = new LinkedList<>(); LinkedList listExpected = new LinkedList<>(); for (int i = 0; i < 10; i++) { listExpected.add("test"); - listFutures.add(Futures.future(new Callable() { - public String call() { - return "test"; - } - }, system.dispatcher())); + listFutures.add( + Futures.future( + new Callable() { + public String call() { + return "test"; + } + }, + system.dispatcher())); } Future> futureList = Futures.sequence(listFutures, system.dispatcher()); @@ -192,53 +214,68 @@ public String call() { // TODO: Improve this test, perhaps with an Actor @Test - public void foldForJavaApiMustWork() throws Exception{ + public void foldForJavaApiMustWork() throws Exception { LinkedList> listFutures = new LinkedList<>(); StringBuilder expected = new StringBuilder(); for (int i = 0; i < 10; i++) { expected.append("test"); - listFutures.add(Futures.future(new Callable() { - public String call() { - return "test"; - } - }, system.dispatcher())); + listFutures.add( + Futures.future( + new Callable() { + public String call() { + return "test"; + } + }, + system.dispatcher())); } - Future result = Futures.fold("", listFutures, new Function2() { - public String apply(String r, String t) { - return r + t; - } - }, system.dispatcher()); + Future result = + Futures.fold( + "", + listFutures, + new Function2() { + public String apply(String r, String t) { + return r + t; + } + }, + system.dispatcher()); assertEquals(expected.toString(), Await.result(result, timeout)); } @Test - public void reduceForJavaApiMustWork() throws Exception{ + public void reduceForJavaApiMustWork() throws Exception { LinkedList> listFutures = new LinkedList<>(); StringBuilder expected = new StringBuilder(); for (int i = 0; i < 10; i++) { expected.append("test"); - listFutures.add(Futures.future(new Callable() { - public String call() { - return "test"; - } - }, system.dispatcher())); + listFutures.add( + Futures.future( + new Callable() { + public String call() { + return "test"; + } + }, + system.dispatcher())); } - Future result = Futures.reduce(listFutures, new Function2() { - public String apply(String r, String t) { - return r + t; - } - }, system.dispatcher()); + Future result = + Futures.reduce( + listFutures, + new Function2() { + public String apply(String r, String t) { + return r + t; + } + }, + system.dispatcher()); assertEquals(expected.toString(), Await.result(result, timeout)); } @Test - public void traverseForJavaApiMustWork() throws Exception{ + public void traverseForJavaApiMustWork() throws Exception { LinkedList listStrings = new LinkedList<>(); LinkedList expectedStrings = new LinkedList<>(); @@ -247,36 +284,49 @@ public void traverseForJavaApiMustWork() throws Exception{ listStrings.add("test"); } - Future> result = Futures.traverse(listStrings, new Function>() { - public Future apply(final String r) { - return Futures.future(new Callable() { - public String call() { - return r.toUpperCase(); - } - }, system.dispatcher()); - } - }, system.dispatcher()); + Future> result = + Futures.traverse( + listStrings, + new Function>() { + public Future apply(final String r) { + return Futures.future( + new Callable() { + public String call() { + return r.toUpperCase(); + } + }, + system.dispatcher()); + } + }, + system.dispatcher()); assertEquals(expectedStrings, Await.result(result, timeout)); } @Test - public void findForJavaApiMustWork() throws Exception{ + public void findForJavaApiMustWork() throws Exception { LinkedList> listFutures = new LinkedList<>(); for (int i = 0; i < 10; i++) { final Integer fi = i; - listFutures.add(Futures.future(new Callable() { - public Integer call() { - return fi; - } - }, system.dispatcher())); + listFutures.add( + Futures.future( + new Callable() { + public Integer call() { + return fi; + } + }, + system.dispatcher())); } final Integer expect = 5; - Future> f = Futures.find(listFutures, new Function() { - public Boolean apply(Integer i) { - return i == 5; - } - }, system.dispatcher()); + Future> f = + Futures.find( + listFutures, + new Function() { + public Boolean apply(Integer i) { + return i == 5; + } + }, + system.dispatcher()); assertEquals(expect, Await.result(f, timeout).get()); } @@ -304,31 +354,35 @@ public void mapToMustBeCallable() throws Exception { public void recoverToMustBeCallable() throws Exception { final IllegalStateException fail = new IllegalStateException("OHNOES"); Promise p = Futures.promise(); - Future f = p.future().recover(new Recover() { - public Object recover(Throwable t) throws Throwable { - if (t == fail) - return "foo"; - else - throw t; - } - }, system.dispatcher()); + Future f = + p.future() + .recover( + new Recover() { + public Object recover(Throwable t) throws Throwable { + if (t == fail) return "foo"; + else throw t; + } + }, + system.dispatcher()); Duration d = Duration.create(1, TimeUnit.SECONDS); p.failure(fail); assertEquals("foo", Await.result(f, d)); } @Test - public void recoverWithToMustBeCallable() throws Exception{ + public void recoverWithToMustBeCallable() throws Exception { final IllegalStateException fail = new IllegalStateException("OHNOES"); Promise p = Futures.promise(); - Future f = p.future().recoverWith(new Recover>() { - public Future recover(Throwable t) throws Throwable { - if (t == fail) - return Futures.successful("foo"); - else - throw t; - } - }, system.dispatcher()); + Future f = + p.future() + .recoverWith( + new Recover>() { + public Future recover(Throwable t) throws Throwable { + if (t == fail) return Futures.successful("foo"); + else throw t; + } + }, + system.dispatcher()); Duration d = Duration.create(1, TimeUnit.SECONDS); p.failure(fail); assertEquals("foo", Await.result(f, d));