aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlmaz Mingaleev <mingaleev@google.com>2024-03-27 14:06:08 +0000
committerAlmaz Mingaleev <mingaleev@google.com>2024-03-27 14:06:08 +0000
commit336b9601190aa9f8b63409ce3c9fd7c22e4ae825 (patch)
tree4f6fb72f5a63ef04f9b0c0c85a50aa0de7e57e1e
parent9bd515ee66387b04b3ddf8ac4d83df3bcd39dd8c (diff)
downloadlibcore-336b9601190aa9f8b63409ce3c9fd7c22e4ae825.tar.gz
Import test.java.util.ServiceLoader.basic from jdk-17.0.10-ga
List of files: ojluni/src/test/java/util/ServiceLoader/basic/Basic.java ojluni/src/test/java/util/ServiceLoader/basic/FooProvider1.java ojluni/src/test/java/util/ServiceLoader/basic/FooProvider2.java ojluni/src/test/java/util/ServiceLoader/basic/FooProvider3.java ojluni/src/test/java/util/ServiceLoader/basic/FooService.java Generated by tools/expected_upstream/ojluni_merge_to_main.py Bug: 330776328 Test: N/A No-Typo-Check: Imported files Change-Id: Ib28138751d80c4f261299707044d7d77563bfee3
-rw-r--r--EXPECTED_UPSTREAM5
-rw-r--r--ojluni/src/test/java/util/ServiceLoader/basic/Basic.java92
-rw-r--r--ojluni/src/test/java/util/ServiceLoader/basic/FooProvider1.java24
-rw-r--r--ojluni/src/test/java/util/ServiceLoader/basic/FooProvider2.java24
-rw-r--r--ojluni/src/test/java/util/ServiceLoader/basic/FooProvider3.java24
-rw-r--r--ojluni/src/test/java/util/ServiceLoader/basic/FooService.java24
6 files changed, 193 insertions, 0 deletions
diff --git a/EXPECTED_UPSTREAM b/EXPECTED_UPSTREAM
index d69a8d08a91..5ce6c8f7cf0 100644
--- a/EXPECTED_UPSTREAM
+++ b/EXPECTED_UPSTREAM
@@ -2527,6 +2527,11 @@ ojluni/src/test/java/util/SequencedCollection/SimpleDeque.java,jdk21u/jdk-21.0.1
ojluni/src/test/java/util/SequencedCollection/SimpleList.java,jdk21u/jdk-21.0.1-ga,test/jdk/java/util/SequencedCollection/SimpleList.java
ojluni/src/test/java/util/SequencedCollection/SimpleSortedMap.java,jdk21u/jdk-21.0.1-ga,test/jdk/java/util/SequencedCollection/SimpleSortedMap.java
ojluni/src/test/java/util/SequencedCollection/SimpleSortedSet.java,jdk21u/jdk-21.0.1-ga,test/jdk/java/util/SequencedCollection/SimpleSortedSet.java
+ojluni/src/test/java/util/ServiceLoader/basic/Basic.java,jdk17u/jdk-17.0.10-ga,test/jdk/java/util/ServiceLoader/basic/Basic.java
+ojluni/src/test/java/util/ServiceLoader/basic/FooProvider1.java,jdk17u/jdk-17.0.10-ga,test/jdk/java/util/ServiceLoader/basic/FooProvider1.java
+ojluni/src/test/java/util/ServiceLoader/basic/FooProvider2.java,jdk17u/jdk-17.0.10-ga,test/jdk/java/util/ServiceLoader/basic/FooProvider2.java
+ojluni/src/test/java/util/ServiceLoader/basic/FooProvider3.java,jdk17u/jdk-17.0.10-ga,test/jdk/java/util/ServiceLoader/basic/FooProvider3.java
+ojluni/src/test/java/util/ServiceLoader/basic/FooService.java,jdk17u/jdk-17.0.10-ga,test/jdk/java/util/ServiceLoader/basic/FooService.java
ojluni/src/test/java/util/StringJoiner/MergeTest.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/util/StringJoiner/MergeTest.java
ojluni/src/test/java/util/StringJoiner/StringJoinerTest.java,jdk11u/jdk-11.0.13-ga,test/jdk/java/util/StringJoiner/StringJoinerTest.java
ojluni/src/test/java/util/Timer/Args.java,jdk17u/jdk-17.0.6-ga,test/jdk/java/util/Timer/Args.java
diff --git a/ojluni/src/test/java/util/ServiceLoader/basic/Basic.java b/ojluni/src/test/java/util/ServiceLoader/basic/Basic.java
new file mode 100644
index 00000000000..0d3cc2c2131
--- /dev/null
+++ b/ojluni/src/test/java/util/ServiceLoader/basic/Basic.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//
+
+import java.io.*;
+import java.util.*;
+
+
+public class Basic {
+
+ private static PrintStream out = System.err;
+
+ private static <T> Set<T> setOf(Iterable<T> it) {
+ Set<T> s = new HashSet<T>();
+ for (T t : it)
+ s.add(t);
+ return s;
+ }
+
+ private static <T> void checkEquals(Set<T> s1, Set<T> s2, boolean eq) {
+ if (s1.equals(s2) != eq)
+ throw new RuntimeException(String.format("%b %s : %s",
+ eq, s1, s2));
+ }
+
+ abstract static class TestLoader {
+ String name;
+
+ TestLoader(String name) { this.name = name; }
+
+ abstract ServiceLoader<FooService> load();
+ }
+
+ static TestLoader tcclLoader = new TestLoader("Thread context class loader") {
+ ServiceLoader<FooService> load() {
+ return ServiceLoader.load(FooService.class);
+ }
+ };
+
+ static TestLoader systemClLoader = new TestLoader("System class loader") {
+ ServiceLoader<FooService> load() {
+ return ServiceLoader.load(FooService.class, ClassLoader.getSystemClassLoader());
+ }
+ };
+
+ static TestLoader nullClLoader = new TestLoader("null (defer to system class loader)") {
+ ServiceLoader<FooService> load() {
+ return ServiceLoader.load(FooService.class, null);
+ }
+ };
+
+ public static void main(String[] args) {
+ for (TestLoader tl : Arrays.asList(tcclLoader, systemClLoader, nullClLoader)) {
+ test(tl);
+ }
+ }
+
+ static void test(TestLoader tl) {
+ ServiceLoader<FooService> sl = tl.load();
+ out.format("%s: %s%n", tl.name, sl);
+
+ // Providers are cached
+ Set<FooService> ps = setOf(sl);
+ checkEquals(ps, setOf(sl), true);
+
+ // The cache can be flushed and reloaded
+ sl.reload();
+ checkEquals(ps, setOf(sl), false);
+
+ }
+}
diff --git a/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider1.java b/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider1.java
new file mode 100644
index 00000000000..dcc4c362bc3
--- /dev/null
+++ b/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider1.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public class FooProvider1 extends FooService { }
diff --git a/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider2.java b/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider2.java
new file mode 100644
index 00000000000..edca4794137
--- /dev/null
+++ b/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider2.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public class FooProvider2 extends FooService { }
diff --git a/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider3.java b/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider3.java
new file mode 100644
index 00000000000..78b1c63255f
--- /dev/null
+++ b/ojluni/src/test/java/util/ServiceLoader/basic/FooProvider3.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public class FooProvider3 extends FooService { }
diff --git a/ojluni/src/test/java/util/ServiceLoader/basic/FooService.java b/ojluni/src/test/java/util/ServiceLoader/basic/FooService.java
new file mode 100644
index 00000000000..27498f38c14
--- /dev/null
+++ b/ojluni/src/test/java/util/ServiceLoader/basic/FooService.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+public abstract class FooService { }