author | chegar |
Sat, 24 Feb 2018 11:27:11 +0000 | |
branch | http-client-branch |
changeset 56167 | 96fa4f49a9ff |
parent 56164 | 4db4bec0e5bb |
child 56451 | 9585061fdb04 |
permissions | -rw-r--r-- |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
1 |
/* |
56159
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
4 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
8 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
14 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
18 |
* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
21 |
* questions. |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
22 |
*/ |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
23 |
|
56163
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
24 |
import java.net.http.HttpClient; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
25 |
import java.net.http.HttpRequest; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
26 |
import java.net.http.HttpResponse; |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
27 |
import java.nio.ByteBuffer; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
28 |
import java.nio.MappedByteBuffer; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
29 |
import java.util.Collection; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
30 |
import java.util.List; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
31 |
import java.util.concurrent.Flow; |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
32 |
import java.util.function.Function; |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
33 |
import java.net.http.HttpRequest.BodyPublishers; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
48408
diff
changeset
|
34 |
import java.net.http.HttpResponse.BodyHandler; |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
35 |
import java.net.http.HttpResponse.BodyHandlers; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
48408
diff
changeset
|
36 |
import java.net.http.HttpResponse.BodySubscriber; |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
37 |
import java.net.http.HttpResponse.BodySubscribers; |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
38 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
39 |
/* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
40 |
* @test |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
41 |
* @summary Basic test for Flow adapters with generic type parameters |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
42 |
* @compile FlowAdaptersCompileOnly.java |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
43 |
*/ |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
44 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
45 |
public class FlowAdaptersCompileOnly { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
46 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
47 |
static void makesSureDifferentGenericSignaturesCompile() { |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
48 |
BodyPublishers.fromPublisher(new BBPublisher()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
49 |
BodyPublishers.fromPublisher(new MBBPublisher()); |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
50 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
51 |
BodyHandlers.fromSubscriber(new ListSubscriber()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
52 |
BodyHandlers.fromSubscriber(new CollectionSubscriber()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
53 |
BodyHandlers.fromSubscriber(new IterableSubscriber()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
54 |
BodyHandlers.fromSubscriber(new ObjectSubscriber()); |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
55 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
56 |
BodySubscribers.fromSubscriber(new ListSubscriber()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
57 |
BodySubscribers.fromSubscriber(new CollectionSubscriber()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
58 |
BodySubscribers.fromSubscriber(new IterableSubscriber()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
59 |
BodySubscribers.fromSubscriber(new ObjectSubscriber()); |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
60 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
61 |
BodyPublishers.fromPublisher(new BBPublisher(), 1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
62 |
BodyPublishers.fromPublisher(new MBBPublisher(), 1); |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
63 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
64 |
BodyHandlers.fromSubscriber(new ListSubscriber(), Function.identity()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
65 |
BodyHandlers.fromSubscriber(new CollectionSubscriber(), Function.identity()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
66 |
BodyHandlers.fromSubscriber(new IterableSubscriber(), Function.identity()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
67 |
BodyHandlers.fromSubscriber(new ObjectSubscriber(), Function.identity()); |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
68 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
69 |
BodySubscribers.fromSubscriber(new ListSubscriber(), Function.identity()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
70 |
BodySubscribers.fromSubscriber(new CollectionSubscriber(), Function.identity()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
71 |
BodySubscribers.fromSubscriber(new IterableSubscriber(), Function.identity()); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
72 |
BodySubscribers.fromSubscriber(new ObjectSubscriber(), Function.identity()); |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
73 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
74 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
75 |
static class BBPublisher implements Flow.Publisher<ByteBuffer> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
76 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
77 |
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
78 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
79 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
80 |
static class MBBPublisher implements Flow.Publisher<MappedByteBuffer> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
81 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
82 |
public void subscribe(Flow.Subscriber<? super MappedByteBuffer> subscriber) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
83 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
84 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
85 |
static class ListSubscriber implements Flow.Subscriber<List<ByteBuffer>> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
86 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
87 |
@Override public void onNext(List<ByteBuffer> item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
88 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
89 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
90 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
91 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
92 |
static class CollectionSubscriber implements Flow.Subscriber<Collection<ByteBuffer>> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
93 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
94 |
@Override public void onNext(Collection<ByteBuffer> item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
95 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
96 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
97 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
98 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
99 |
static class IterableSubscriber implements Flow.Subscriber<Iterable<ByteBuffer>> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
100 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
101 |
@Override public void onNext(Iterable<ByteBuffer> item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
102 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
103 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
104 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
105 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
106 |
static class ObjectSubscriber implements Flow.Subscriber<Object> { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
107 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
108 |
@Override public void onNext(Object item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
109 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
110 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
111 |
} |
56159
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
112 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
113 |
// --- |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
114 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
115 |
static final Function<ListSubscriber,Integer> f1 = subscriber -> 1; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
116 |
static final Function<ListSubscriber,Number> f2 = subscriber -> 2; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
117 |
static final Function<ListSubscriberX,Integer> f3 = subscriber -> 3; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
118 |
static final Function<ListSubscriberX,Number> f4 = subscriber -> 4; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
119 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
120 |
static class ListSubscriberX extends ListSubscriber { |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
121 |
int getIntegerX() { return 5; } |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
122 |
} |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
123 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
124 |
static void makesSureDifferentGenericFunctionSignaturesCompile() { |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
125 |
BodyHandler<Integer> bh01 = BodyHandlers.fromSubscriber(new ListSubscriber(), s -> 6); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
126 |
BodyHandler<Number> bh02 = BodyHandlers.fromSubscriber(new ListSubscriber(), s -> 7); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
127 |
BodyHandler<Integer> bh03 = BodyHandlers.fromSubscriber(new ListSubscriber(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
128 |
BodyHandler<Number> bh04 = BodyHandlers.fromSubscriber(new ListSubscriber(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
129 |
BodyHandler<Number> bh05 = BodyHandlers.fromSubscriber(new ListSubscriber(), f2); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
130 |
BodyHandler<Integer> bh06 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
131 |
BodyHandler<Number> bh07 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
132 |
BodyHandler<Number> bh08 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f2); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
133 |
BodyHandler<Integer> bh09 = BodyHandlers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
134 |
BodyHandler<Number> bh10 = BodyHandlers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
135 |
BodyHandler<Integer> bh11 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f3); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
136 |
BodyHandler<Number> bh12 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f3); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
137 |
BodyHandler<Number> bh13 = BodyHandlers.fromSubscriber(new ListSubscriberX(), f4); |
56159
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
138 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
139 |
BodySubscriber<Integer> bs01 = BodySubscribers.fromSubscriber(new ListSubscriber(), s -> 6); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
140 |
BodySubscriber<Number> bs02 = BodySubscribers.fromSubscriber(new ListSubscriber(), s -> 7); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
141 |
BodySubscriber<Integer> bs03 = BodySubscribers.fromSubscriber(new ListSubscriber(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
142 |
BodySubscriber<Number> bs04 = BodySubscribers.fromSubscriber(new ListSubscriber(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
143 |
BodySubscriber<Number> bs05 = BodySubscribers.fromSubscriber(new ListSubscriber(), f2); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
144 |
BodySubscriber<Integer> bs06 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
145 |
BodySubscriber<Number> bs07 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f1); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
146 |
BodySubscriber<Number> bs08 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f2); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
147 |
BodySubscriber<Integer> bs09 = BodySubscribers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
148 |
BodySubscriber<Number> bs10 = BodySubscribers.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
149 |
BodySubscriber<Integer> bs11 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f3); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
150 |
BodySubscriber<Number> bs12 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f3); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
151 |
BodySubscriber<Number> bs13 = BodySubscribers.fromSubscriber(new ListSubscriberX(), f4); |
56159
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
152 |
} |
56163
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
153 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
154 |
// --- |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
155 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
156 |
static class NumberSubscriber implements Flow.Subscriber<List<ByteBuffer>> { |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
157 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
158 |
@Override public void onNext(List<ByteBuffer> item) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
159 |
@Override public void onError(Throwable throwable) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
160 |
@Override public void onComplete() { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
161 |
public Number getNumber() { return null; } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
162 |
} |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
163 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
164 |
static class IntegerSubscriber extends NumberSubscriber { |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
165 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
166 |
@Override public void onNext(List<ByteBuffer> item) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
167 |
@Override public void onError(Throwable throwable) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
168 |
@Override public void onComplete() { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
169 |
public Integer getInteger() { return null; } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
170 |
} |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
171 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
172 |
static class LongSubscriber extends NumberSubscriber { |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
173 |
@Override public void onSubscribe(Flow.Subscription subscription) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
174 |
@Override public void onNext(List<ByteBuffer> item) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
175 |
@Override public void onError(Throwable throwable) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
176 |
@Override public void onComplete() { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
177 |
public Long getLong() { return null; } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
178 |
} |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
179 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
180 |
static final Function<NumberSubscriber,Number> numMapper = sub -> sub.getNumber(); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
181 |
static final Function<IntegerSubscriber,Integer> intMapper = sub -> sub.getInteger(); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
182 |
static final Function<LongSubscriber,Long> longMapper = sub -> sub.getLong(); |
56164
4db4bec0e5bb
http-client-branch: trivial test whitespace cleanup
chegar
parents:
56163
diff
changeset
|
183 |
|
56163
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
184 |
public void makesSureDifferentGenericSubscriberSignaturesCompile() |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
185 |
throws Exception |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
186 |
{ |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
187 |
HttpClient client = null; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
188 |
HttpRequest request = null; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
189 |
IntegerSubscriber sub1 = new IntegerSubscriber(); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
190 |
|
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
191 |
HttpResponse<Integer> r1 = client.send(request, BodyHandlers.fromSubscriber(sub1, IntegerSubscriber::getInteger)); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
192 |
HttpResponse<Number> r2 = client.send(request, BodyHandlers.fromSubscriber(sub1, IntegerSubscriber::getInteger)); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
193 |
HttpResponse<Number> r3 = client.send(request, BodyHandlers.fromSubscriber(sub1, NumberSubscriber::getNumber)); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
194 |
HttpResponse<Integer> r4 = client.send(request, BodyHandlers.fromSubscriber(sub1, intMapper)); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
195 |
HttpResponse<Number> r5 = client.send(request, BodyHandlers.fromSubscriber(sub1, intMapper)); |
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
196 |
HttpResponse<Number> r6 = client.send(request, BodyHandlers.fromSubscriber(sub1, numMapper)); |
56163
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
197 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
198 |
// compiles but makes little sense. Just what you get with any usage of `? super` |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
199 |
final Function<Object,Number> objectMapper = sub -> 1; |
56167
96fa4f49a9ff
http-client-branch: CSR review commet - outboard pre-defined BP/BH/BS
chegar
parents:
56164
diff
changeset
|
200 |
client.sendAsync(request, BodyHandlers.fromSubscriber(sub1, objectMapper)); |
56163
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
201 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
202 |
// does not compile, as expected ( uncomment to see ) |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
203 |
//HttpResponse<Number> r7 = client.send(request, BodyHandler.fromSubscriber(sub1, longMapper)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
204 |
} |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
205 |
} |