author | chegar |
Thu, 22 Feb 2018 12:23:53 +0000 | |
branch | http-client-branch |
changeset 56163 | 9efadce38a17 |
parent 56159 | 039ab5a71a5c |
child 56164 | 4db4bec0e5bb |
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; |
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
48408
diff
changeset
|
33 |
import java.net.http.HttpRequest.BodyPublisher; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
48408
diff
changeset
|
34 |
import java.net.http.HttpResponse.BodyHandler; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
48408
diff
changeset
|
35 |
import java.net.http.HttpResponse.BodySubscriber; |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
36 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
37 |
/* |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
38 |
* @test |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
39 |
* @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
|
40 |
* @compile FlowAdaptersCompileOnly.java |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
41 |
*/ |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
42 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
43 |
public class FlowAdaptersCompileOnly { |
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 |
static void makesSureDifferentGenericSignaturesCompile() { |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
46 |
BodyPublisher.fromPublisher(new BBPublisher()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
47 |
BodyPublisher.fromPublisher(new MBBPublisher()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
48 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
49 |
BodyHandler.fromSubscriber(new ListSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
50 |
BodyHandler.fromSubscriber(new CollectionSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
51 |
BodyHandler.fromSubscriber(new IterableSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
52 |
BodyHandler.fromSubscriber(new ObjectSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
53 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
54 |
BodySubscriber.fromSubscriber(new ListSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
55 |
BodySubscriber.fromSubscriber(new CollectionSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
56 |
BodySubscriber.fromSubscriber(new IterableSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
57 |
BodySubscriber.fromSubscriber(new ObjectSubscriber()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
58 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
59 |
BodyPublisher.fromPublisher(new BBPublisher(), 1); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
60 |
BodyPublisher.fromPublisher(new MBBPublisher(), 1); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
61 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
62 |
BodyHandler.fromSubscriber(new ListSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
63 |
BodyHandler.fromSubscriber(new CollectionSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
64 |
BodyHandler.fromSubscriber(new IterableSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
65 |
BodyHandler.fromSubscriber(new ObjectSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
66 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
67 |
BodySubscriber.fromSubscriber(new ListSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
68 |
BodySubscriber.fromSubscriber(new CollectionSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
69 |
BodySubscriber.fromSubscriber(new IterableSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
70 |
BodySubscriber.fromSubscriber(new ObjectSubscriber(), Function.identity()); |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
71 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
72 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
73 |
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
|
74 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
75 |
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
|
76 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
77 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
78 |
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
|
79 |
@Override |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
80 |
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
|
81 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
82 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
83 |
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
|
84 |
@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
|
85 |
@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
|
86 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
87 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
88 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
89 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
90 |
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
|
91 |
@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
|
92 |
@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
|
93 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
94 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
95 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
96 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
97 |
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
|
98 |
@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
|
99 |
@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
|
100 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
101 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
102 |
} |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
103 |
|
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
104 |
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
|
105 |
@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
|
106 |
@Override public void onNext(Object item) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
107 |
@Override public void onError(Throwable throwable) { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
108 |
@Override public void onComplete() { } |
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
109 |
} |
56159
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
110 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
111 |
// --- |
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 |
static final Function<ListSubscriber,Integer> f1 = subscriber -> 1; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
114 |
static final Function<ListSubscriber,Number> f2 = subscriber -> 2; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
115 |
static final Function<ListSubscriberX,Integer> f3 = subscriber -> 3; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
116 |
static final Function<ListSubscriberX,Number> f4 = subscriber -> 4; |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
117 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
118 |
static class ListSubscriberX extends ListSubscriber { |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
119 |
int getIntegerX() { return 5; } |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
120 |
} |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
121 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
122 |
static void makesSureDifferentGenericFunctionSignaturesCompile() { |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
123 |
BodyHandler<Integer> bh01 = BodyHandler.fromSubscriber(new ListSubscriber(), s -> 6); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
124 |
BodyHandler<Number> bh02 = BodyHandler.fromSubscriber(new ListSubscriber(), s -> 7); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
125 |
BodyHandler<Integer> bh03 = BodyHandler.fromSubscriber(new ListSubscriber(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
126 |
BodyHandler<Number> bh04 = BodyHandler.fromSubscriber(new ListSubscriber(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
127 |
BodyHandler<Number> bh05 = BodyHandler.fromSubscriber(new ListSubscriber(), f2); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
128 |
BodyHandler<Integer> bh06 = BodyHandler.fromSubscriber(new ListSubscriberX(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
129 |
BodyHandler<Number> bh07 = BodyHandler.fromSubscriber(new ListSubscriberX(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
130 |
BodyHandler<Number> bh08 = BodyHandler.fromSubscriber(new ListSubscriberX(), f2); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
131 |
BodyHandler<Integer> bh09 = BodyHandler.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
132 |
BodyHandler<Number> bh10 = BodyHandler.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
133 |
BodyHandler<Integer> bh11 = BodyHandler.fromSubscriber(new ListSubscriberX(), f3); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
134 |
BodyHandler<Number> bh12 = BodyHandler.fromSubscriber(new ListSubscriberX(), f3); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
135 |
BodyHandler<Number> bh13 = BodyHandler.fromSubscriber(new ListSubscriberX(), f4); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
136 |
|
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
137 |
BodySubscriber<Integer> bs01 = BodySubscriber.fromSubscriber(new ListSubscriber(), s -> 6); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
138 |
BodySubscriber<Number> bs02 = BodySubscriber.fromSubscriber(new ListSubscriber(), s -> 7); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
139 |
BodySubscriber<Integer> bs03 = BodySubscriber.fromSubscriber(new ListSubscriber(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
140 |
BodySubscriber<Number> bs04 = BodySubscriber.fromSubscriber(new ListSubscriber(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
141 |
BodySubscriber<Number> bs05 = BodySubscriber.fromSubscriber(new ListSubscriber(), f2); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
142 |
BodySubscriber<Integer> bs06 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
143 |
BodySubscriber<Number> bs07 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f1); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
144 |
BodySubscriber<Number> bs08 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f2); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
145 |
BodySubscriber<Integer> bs09 = BodySubscriber.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
146 |
BodySubscriber<Number> bs10 = BodySubscriber.fromSubscriber(new ListSubscriberX(), ListSubscriberX::getIntegerX); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
147 |
BodySubscriber<Integer> bs11 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f3); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
148 |
BodySubscriber<Number> bs12 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f3); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
149 |
BodySubscriber<Number> bs13 = BodySubscriber.fromSubscriber(new ListSubscriberX(), f4); |
039ab5a71a5c
http-client-branch: type paramater review of generic methods
chegar
parents:
56089
diff
changeset
|
150 |
} |
56163
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
151 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
152 |
// --- |
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 |
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
|
155 |
@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
|
156 |
@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
|
157 |
@Override public void onError(Throwable throwable) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
158 |
@Override public void onComplete() { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
159 |
public Number getNumber() { return null; } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
160 |
} |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
161 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
162 |
static class IntegerSubscriber extends NumberSubscriber { |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
163 |
@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
|
164 |
@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
|
165 |
@Override public void onError(Throwable throwable) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
166 |
@Override public void onComplete() { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
167 |
public Integer getInteger() { return null; } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
168 |
} |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
169 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
170 |
static class LongSubscriber extends NumberSubscriber { |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
171 |
@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
|
172 |
@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
|
173 |
@Override public void onError(Throwable throwable) { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
174 |
@Override public void onComplete() { } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
175 |
public Long getLong() { return null; } |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
176 |
} |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
177 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
static final Function<LongSubscriber,Long> longMapper = sub -> sub.getLong(); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
181 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
182 |
public void makesSureDifferentGenericSubscriberSignaturesCompile() |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
183 |
throws Exception |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
184 |
{ |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
185 |
HttpClient client = null; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
186 |
HttpRequest request = null; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
187 |
IntegerSubscriber sub1 = new IntegerSubscriber(); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
188 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
189 |
HttpResponse<Integer> r1 = client.send(request, BodyHandler.fromSubscriber(sub1, IntegerSubscriber::getInteger)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
190 |
HttpResponse<Number> r2 = client.send(request, BodyHandler.fromSubscriber(sub1, IntegerSubscriber::getInteger)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
191 |
HttpResponse<Number> r3 = client.send(request, BodyHandler.fromSubscriber(sub1, NumberSubscriber::getNumber)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
192 |
HttpResponse<Integer> r4 = client.send(request, BodyHandler.fromSubscriber(sub1, intMapper)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
193 |
HttpResponse<Number> r5 = client.send(request, BodyHandler.fromSubscriber(sub1, intMapper)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
194 |
HttpResponse<Number> r6 = client.send(request, BodyHandler.fromSubscriber(sub1, numMapper)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
195 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
196 |
// 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
|
197 |
final Function<Object,Number> objectMapper = sub -> 1; |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
198 |
client.sendAsync(request, BodyHandler.fromSubscriber(sub1, objectMapper)); |
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
199 |
|
9efadce38a17
http-client-branch: more compile-only type param in generic method tests
chegar
parents:
56159
diff
changeset
|
200 |
// 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
|
201 |
//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
|
202 |
} |
48408
4f830b447edf
8193365: Improve interoperability between HTTP Client's BodyPublisher/BodySubscriber and Flow.Subscriber/Publisher
chegar
parents:
diff
changeset
|
203 |
} |