author | shurailine |
Fri, 16 Mar 2018 03:15:35 -0700 | |
changeset 49258 | be0ec3cc0c2a |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
45652 | 1 |
/* |
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @library modules |
|
49258
be0ec3cc0c2a
8199616: Fix @module declarations in tier1 tests
shurailine
parents:
47216
diff
changeset
|
27 |
* @modules jdk.scripting.nashorn |
45652 | 28 |
* @run testng/othervm ReloadTest |
29 |
* @summary Basic test of ServiceLoader.reload |
|
30 |
*/ |
|
31 |
||
32 |
import java.util.ConcurrentModificationException; |
|
33 |
import java.util.Iterator; |
|
34 |
import java.util.List; |
|
35 |
import java.util.ServiceLoader; |
|
36 |
import java.util.ServiceLoader.Provider; |
|
37 |
import java.util.Spliterator; |
|
38 |
import java.util.stream.Collectors; |
|
39 |
import java.util.stream.Stream; |
|
40 |
import static java.util.ServiceLoader.*; |
|
41 |
import javax.script.ScriptEngineFactory; |
|
42 |
||
43 |
import org.testng.annotations.Test; |
|
44 |
import static org.testng.Assert.*; |
|
45 |
||
46 |
@Test |
|
47 |
public class ReloadTest { |
|
48 |
||
49 |
public void testReload() { |
|
50 |
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class); |
|
51 |
List<String> names1 = sl.stream() |
|
52 |
.map(Provider::get) |
|
53 |
.map(ScriptEngineFactory::getEngineName) |
|
54 |
.collect(Collectors.toList()); |
|
55 |
assertFalse(names1.isEmpty()); |
|
56 |
sl.reload(); |
|
57 |
List<String> names2 = sl.stream() |
|
58 |
.map(Provider::get) |
|
59 |
.map(ScriptEngineFactory::getEngineName) |
|
60 |
.collect(Collectors.toList()); |
|
61 |
assertEquals(names1, names2); |
|
62 |
} |
|
63 |
||
64 |
@Test(expectedExceptions = { ConcurrentModificationException.class }) |
|
65 |
public void testIteratorHasNext() { |
|
66 |
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class); |
|
67 |
Iterator<ScriptEngineFactory> iterator = sl.iterator(); |
|
68 |
sl.reload(); |
|
69 |
iterator.hasNext(); |
|
70 |
} |
|
71 |
||
72 |
@Test(expectedExceptions = { ConcurrentModificationException.class }) |
|
73 |
public void testIteratorNext() { |
|
74 |
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class); |
|
75 |
Iterator<ScriptEngineFactory> iterator = sl.iterator(); |
|
76 |
assertTrue(iterator.hasNext()); |
|
77 |
sl.reload(); |
|
78 |
iterator.next(); |
|
79 |
} |
|
80 |
||
81 |
@Test(expectedExceptions = { ConcurrentModificationException.class }) |
|
82 |
public void testStreamFindAny() { |
|
83 |
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class); |
|
84 |
Stream<Provider<ScriptEngineFactory>> stream = sl.stream(); |
|
85 |
sl.reload(); |
|
86 |
stream.findAny(); |
|
87 |
} |
|
88 |
||
89 |
@Test(expectedExceptions = { ConcurrentModificationException.class }) |
|
90 |
public void testSpliteratorTryAdvance() { |
|
91 |
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class); |
|
92 |
Stream<Provider<ScriptEngineFactory>> stream = sl.stream(); |
|
93 |
Spliterator<Provider<ScriptEngineFactory>> spliterator = stream.spliterator(); |
|
94 |
sl.reload(); |
|
95 |
spliterator.tryAdvance(System.out::println); |
|
96 |
} |
|
97 |
||
98 |
} |