Skip to content

Commit 7009e48

Browse files
builder + request - refactor
1 parent 07412a6 commit 7009e48

35 files changed

Lines changed: 1907 additions & 811 deletions

examples/consumer-test/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ val demoApps = mapOf(
3333
"runRetry" to ("com.marketdata.consumer.RetryBehaviorApp" to
3434
"Retry policy, Retry-After header, preflight gate. Needs mock server."),
3535
"runResponse" to ("com.marketdata.consumer.ResponseFeaturesApp" to
36-
"Response<T> surface: predicates, isNoData, rawBody, saveToFile, toString. Needs mock server."),
36+
"MarketDataResponse surface: predicates, isNoData, json, saveToFile, toString. Needs mock server."),
3737
"runConcurrency" to ("com.marketdata.consumer.ConcurrencyApp" to
38-
"§12 / ADR-007: 50-permit semaphore observed end-to-end. Needs mock server.")
38+
"§12 / ADR-007: 50-permit semaphore observed end-to-end. Needs mock server."),
39+
"runOptions" to ("com.marketdata.consumer.OptionsApp" to
40+
"Full options surface: every endpoint + all params, CSV facet, columns projection, Option A. Needs mock server.")
3941
)
4042

4143
demoApps.forEach { (taskName, app) ->

examples/consumer-test/src/main/java/com/marketdata/consumer/ConcurrencyApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.marketdata.consumer.shared.MockServerControl;
55
import com.marketdata.consumer.shared.MockServerControl.Step;
66
import com.marketdata.sdk.MarketDataClient;
7-
import com.marketdata.sdk.Response;
7+
import com.marketdata.sdk.UtilitiesStatusResponse;
88
import com.marketdata.sdk.utilities.ApiStatus;
99
import java.util.ArrayList;
1010
import java.util.List;
@@ -51,7 +51,7 @@ public static void main(String[] args) {
5151
try (var client =
5252
new MarketDataClient("token", MockServerControl.BASE_URL, null, false)) {
5353
long t0 = System.nanoTime();
54-
List<CompletableFuture<Response<ApiStatus>>> futures = new ArrayList<>(fanout);
54+
List<CompletableFuture<UtilitiesStatusResponse>> futures = new ArrayList<>(fanout);
5555
for (int i = 0; i < fanout; i++) {
5656
futures.add(client.utilities().statusAsync());
5757
}

examples/consumer-test/src/main/java/com/marketdata/consumer/ExceptionsApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static void notFound404WithRealError(MockServerControl mock, MarketDataC
8080
Console.info(
8181
"Spec §11: 404 + {\"s\":\"no_data\"} is a SUCCESSFUL response. The SDK returns a");
8282
Console.info(
83-
"Response<T> with isNoData() = true. To see NotFoundError, we'd need a 404 that");
83+
"a MarketDataResponse with isNoData() = true. To see NotFoundError, we'd need a 404 that");
8484
Console.info(
8585
"ISN'T the no-data envelope — but the current routing maps all 404s to a successful");
8686
Console.info(

examples/consumer-test/src/main/java/com/marketdata/consumer/LiveSmokeApp.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import com.marketdata.consumer.shared.Console;
44
import com.marketdata.sdk.MarketDataClient;
5-
import com.marketdata.sdk.Response;
5+
import com.marketdata.sdk.MarketDataResponse;
6+
import com.marketdata.sdk.UtilitiesHeadersResponse;
7+
import com.marketdata.sdk.UtilitiesStatusResponse;
8+
import com.marketdata.sdk.UtilitiesUserResponse;
9+
import java.util.Map;
610
import com.marketdata.sdk.utilities.ApiStatus;
711
import com.marketdata.sdk.utilities.RequestHeaders;
812
import com.marketdata.sdk.utilities.ServiceStatus;
@@ -38,18 +42,18 @@ public static void main(String[] args) {
3842
Console.header("/status/ (sync) — unversioned, no token required");
3943
Console.run(
4044
() -> client.utilities().status(),
41-
r -> "data() has " + r.data().services().size() + " services; " + describe(r));
45+
r -> "data() has " + r.values().size() + " services; " + describe(r));
4246

4347
Console.header("/status/ (async) — same call via the async surface");
4448
Console.run(
4549
() -> joinResponse(client.utilities().statusAsync()),
46-
r -> "data() has " + r.data().services().size() + " services; " + describe(r));
50+
r -> "data() has " + r.values().size() + " services; " + describe(r));
4751

4852
Console.header("/user/ (sync) — needs a token");
4953
Console.run(
5054
() -> client.utilities().user(),
5155
r -> {
52-
User u = r.data();
56+
User u = r.values();
5357
return "requestsRemaining="
5458
+ u.requestsRemaining()
5559
+ ", requestsLimit="
@@ -64,10 +68,10 @@ public static void main(String[] args) {
6468
Console.run(
6569
() -> client.utilities().headers(),
6670
r -> {
67-
RequestHeaders rh = r.data();
68-
String auth = rh.headers().getOrDefault("authorization", "(absent)");
71+
Map<String, String> rh = r.values();
72+
String auth = rh.getOrDefault("authorization", "(absent)");
6973
return "headers="
70-
+ rh.headers().size()
74+
+ rh.size()
7175
+ " entries (authorization echoed back: "
7276
+ auth
7377
+ "); "
@@ -76,9 +80,9 @@ public static void main(String[] args) {
7680

7781
Console.header("Parallel async — fan out 3 calls, await all");
7882
long t0 = System.nanoTime();
79-
CompletableFuture<Response<ApiStatus>> a = client.utilities().statusAsync();
80-
CompletableFuture<Response<User>> b = client.utilities().userAsync();
81-
CompletableFuture<Response<RequestHeaders>> c = client.utilities().headersAsync();
83+
CompletableFuture<UtilitiesStatusResponse> a = client.utilities().statusAsync();
84+
CompletableFuture<UtilitiesUserResponse> b = client.utilities().userAsync();
85+
CompletableFuture<UtilitiesHeadersResponse> c = client.utilities().headersAsync();
8286
// exceptionally() turns a failure into a null sentinel so allOf doesn't short-circuit on
8387
// the first failing call — we still want to see whether the others succeeded.
8488
CompletableFuture<Object> aSafe = a.thenApply(r -> (Object) r).exceptionally(t -> t);
@@ -91,11 +95,11 @@ public static void main(String[] args) {
9195
+ elapsedMs
9296
+ " ms (≈ slowest single call, not sum — proves true parallelism)");
9397
describeResult("status", aSafe.join(), r -> {
94-
List<ServiceStatus> services = ((Response<ApiStatus>) r).data().services();
98+
List<ServiceStatus> services = ((UtilitiesStatusResponse) r).values();
9599
return services.size() + " services; first: " + services.get(0).service();
96100
});
97-
describeResult("user", bSafe.join(), r -> "remaining=" + ((Response<User>) r).data().requestsRemaining());
98-
describeResult("headers", cSafe.join(), r -> ((Response<RequestHeaders>) r).data().headers().size() + " entries");
101+
describeResult("user", bSafe.join(), r -> "remaining=" + ((UtilitiesUserResponse) r).values().requestsRemaining());
102+
describeResult("headers", cSafe.join(), r -> ((UtilitiesHeadersResponse) r).values().size() + " entries");
99103

100104
Console.header("Final rate-limit snapshot");
101105
Console.info("rateLimits after the calls: " + client.getRateLimits());
@@ -112,11 +116,11 @@ private static void describeResult(String label, Object resultOrThrowable, java.
112116
}
113117
}
114118

115-
private static String describe(Response<?> r) {
119+
private static String describe(MarketDataResponse<?> r) {
116120
return "status=" + r.statusCode() + ", requestId=" + r.requestId() + ", url=" + r.requestUrl();
117121
}
118122

119-
private static <T> Response<T> joinResponse(CompletableFuture<Response<T>> f) {
123+
private static <R> R joinResponse(CompletableFuture<R> f) {
120124
// CompletableFuture.join wraps the cause in CompletionException, but the SDK's joinSync
121125
// contract is to surface MarketDataException directly. We mimic that here so the demo's
122126
// exception output matches what a sync caller would see.

0 commit comments

Comments
 (0)