Skip to content

Commit 312de17

Browse files
authored
chore: remove deprecated methods (#316)
* chore: remove deprecated methods
1 parent 5cbb1e8 commit 312de17

File tree

5 files changed

+35
-110
lines changed

5 files changed

+35
-110
lines changed

src/main/java/io/kurrent/dbclient/EventData.java

-24
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,6 @@ public byte[] getUserMetadata() {
5555
return userMetadata;
5656
}
5757

58-
/**
59-
* Configures an event data builder to host a JSON payload.
60-
* @param eventType event's type.
61-
* @param eventData event's payload.
62-
* @return an event data builder.
63-
* @param <A> a type that can be serialized in JSON.
64-
*/
65-
@Deprecated
66-
public static <A> EventDataBuilder builderAsJson(String eventType, A eventData) {
67-
return builderAsJson(null, eventType, eventData);
68-
}
69-
70-
/**
71-
* Configures an event data builder to host a JSON payload.
72-
* @param eventId event's id.
73-
* @param eventType event's type.
74-
* @param eventData event's payload.
75-
* @return an event data builder.
76-
* @param <A> a type that can be serialized in JSON.
77-
*/
78-
public static <A> EventDataBuilder builderAsJson(UUID eventId, String eventType, A eventData) {
79-
return EventDataBuilder.json(eventId, eventType, eventData);
80-
}
81-
8258
/**
8359
* Configures an event data builder to host a JSON payload.
8460
* @param eventType event's type.

src/main/java/io/kurrent/dbclient/EventDataBuilder.java

-45
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,6 @@ public class EventDataBuilder {
1717

1818
EventDataBuilder(){}
1919

20-
/**
21-
* Configures builder to serialize event data as JSON.
22-
* @param eventType event's type.
23-
* @param eventData event's payload.
24-
* @return an event data builder.
25-
* @param <A> a type that can be serialized in JSON.
26-
*/
27-
public static <A> EventDataBuilder json(String eventType, A eventData) {
28-
return json(null, eventType, eventData);
29-
}
30-
31-
/**
32-
* Configures an event data builder to host a JSON payload.
33-
* @param id event's id.
34-
* @param eventType event's type.
35-
* @param eventData event's payload.
36-
* @return an event data builder.
37-
* @param <A> a type that can be serialized in JSON.
38-
*/
39-
@Deprecated
40-
public static <A> EventDataBuilder json(UUID id, String eventType, A eventData) {
41-
try {
42-
JsonMapper mapper = new JsonMapper();
43-
return json(id, eventType, mapper.writeValueAsBytes(eventData));
44-
} catch (JsonProcessingException e) {
45-
throw new RuntimeException(e);
46-
}
47-
}
48-
4920
/**
5021
* Configures an event data builder to host a JSON payload.
5122
* @param eventType event's type.
@@ -115,22 +86,6 @@ public EventDataBuilder eventId(UUID id) {
11586
return this;
11687
}
11788

118-
/**
119-
* Sets event's custom user metadata.
120-
* @param <A> an object that can be serialized in JSON.
121-
*/
122-
@Deprecated
123-
public <A> EventDataBuilder metadataAsJson(A value) {
124-
try {
125-
JsonMapper mapper = new JsonMapper();
126-
this.metadata = mapper.writeValueAsBytes(value);
127-
} catch (JsonProcessingException e) {
128-
throw new RuntimeException(e);
129-
}
130-
131-
return this;
132-
}
133-
13489
/**
13590
* Sets event's custom user metadata.
13691
*/

src/test/java/io/kurrent/dbclient/samples/appending_events/AppendingEvents.java

+26-33
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package io.kurrent.dbclient.samples.appending_events;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
34
import io.kurrent.dbclient.*;
45
import io.kurrent.dbclient.samples.TestEvent;
56

67
import java.util.UUID;
78
import java.util.concurrent.ExecutionException;
89

10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
12+
913
public class AppendingEvents {
10-
private static void appendToStream(KurrentDBClient client) throws ExecutionException, InterruptedException {
14+
private static void appendToStream(KurrentDBClient client) throws ExecutionException, InterruptedException, JsonProcessingException {
1115
// region append-to-stream
16+
ObjectMapper objectMapper = new ObjectMapper();
17+
1218
EventData eventData = EventData
1319
.builderAsJson(
1420
UUID.randomUUID(),
1521
"some-event",
16-
new TestEvent(
17-
"1",
18-
"some value"
19-
))
22+
objectMapper.writeValueAsBytes(new TestEvent("1", "some value"))
23+
)
2024
.build();
2125

2226
AppendToStreamOptions options = AppendToStreamOptions.get()
@@ -27,16 +31,15 @@ private static void appendToStream(KurrentDBClient client) throws ExecutionExcep
2731
// endregion append-to-stream
2832
}
2933

30-
private static void appendWithSameId(KurrentDBClient client) throws ExecutionException, InterruptedException {
34+
private static void appendWithSameId(KurrentDBClient client) throws ExecutionException, InterruptedException, JsonProcessingException {
3135
// region append-duplicate-event
36+
ObjectMapper objectMapper = new ObjectMapper();
37+
3238
EventData eventData = EventData
3339
.builderAsJson(
3440
UUID.randomUUID(),
3541
"some-event",
36-
new TestEvent(
37-
"1",
38-
"some value"
39-
))
42+
objectMapper.writeValueAsBytes(new TestEvent("1", "some value")))
4043
.build();
4144

4245
AppendToStreamOptions options = AppendToStreamOptions.get()
@@ -51,26 +54,22 @@ private static void appendWithSameId(KurrentDBClient client) throws ExecutionExc
5154
// endregion append-duplicate-event
5255
}
5356

54-
private static void appendWithNoStream(KurrentDBClient client) throws ExecutionException, InterruptedException {
57+
private static void appendWithNoStream(KurrentDBClient client) throws ExecutionException, InterruptedException, JsonProcessingException {
5558
// region append-with-no-stream
59+
ObjectMapper objectMapper = new ObjectMapper();
60+
5661
EventData eventDataOne = EventData
5762
.builderAsJson(
5863
UUID.randomUUID(),
5964
"some-event",
60-
new TestEvent(
61-
"1",
62-
"some value"
63-
))
65+
objectMapper.writeValueAsBytes(new TestEvent("1", "some value")))
6466
.build();
6567

6668
EventData eventDataTwo = EventData
6769
.builderAsJson(
6870
UUID.randomUUID(),
6971
"some-event",
70-
new TestEvent(
71-
"2",
72-
"some other value"
73-
))
72+
objectMapper.writeValueAsBytes(new TestEvent("2", "some other value")))
7473
.build();
7574

7675
AppendToStreamOptions options = AppendToStreamOptions.get()
@@ -85,8 +84,9 @@ private static void appendWithNoStream(KurrentDBClient client) throws ExecutionE
8584
// endregion append-with-no-stream
8685
}
8786

88-
private static void appendWithConcurrencyCheck(KurrentDBClient client) throws ExecutionException, InterruptedException {
87+
private static void appendWithConcurrencyCheck(KurrentDBClient client) throws ExecutionException, InterruptedException, JsonProcessingException {
8988
// region append-with-concurrency-check
89+
ObjectMapper objectMapper = new ObjectMapper();
9090

9191
ReadStreamOptions readStreamOptions = ReadStreamOptions.get()
9292
.forwards()
@@ -99,20 +99,14 @@ private static void appendWithConcurrencyCheck(KurrentDBClient client) throws Ex
9999
.builderAsJson(
100100
UUID.randomUUID(),
101101
"some-event",
102-
new TestEvent(
103-
"1",
104-
"clientOne"
105-
))
102+
objectMapper.writeValueAsBytes(new TestEvent("1", "clientOne")))
106103
.build();
107104

108105
EventData clientTwoData = EventData
109106
.builderAsJson(
110107
UUID.randomUUID(),
111108
"some-event",
112-
new TestEvent(
113-
"2",
114-
"clientTwo"
115-
))
109+
objectMapper.writeValueAsBytes(new TestEvent("2", "clientTwo")))
116110
.build();
117111

118112

@@ -127,15 +121,14 @@ private static void appendWithConcurrencyCheck(KurrentDBClient client) throws Ex
127121
// endregion append-with-concurrency-check
128122
}
129123

130-
public void appendOverridingUserCredentials(KurrentDBClient client) throws ExecutionException, InterruptedException {
124+
public void appendOverridingUserCredentials(KurrentDBClient client) throws ExecutionException, InterruptedException, JsonProcessingException {
125+
ObjectMapper objectMapper = new ObjectMapper();
126+
131127
EventData eventData = EventData
132128
.builderAsJson(
133129
UUID.randomUUID(),
134130
"some-event",
135-
new TestEvent(
136-
"1",
137-
"some value"
138-
))
131+
objectMapper.writeValueAsBytes(new TestEvent("1", "some value")))
139132
.build();
140133
//region overriding-user-credentials
141134
UserCredentials credentials = new UserCredentials("admin", "changeit");

src/test/java/io/kurrent/dbclient/samples/opentelemetry/Instrumentation.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package io.kurrent.dbclient.samples.opentelemetry;
2+
import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException;
23

34
import io.kurrent.dbclient.*;
45
import io.kurrent.dbclient.samples.TestEvent;
@@ -9,6 +10,7 @@
910
import io.opentelemetry.sdk.resources.Resource;
1011
import io.opentelemetry.sdk.trace.SdkTracerProvider;
1112
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
13+
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
1214
// endregion import-required-packages
1315

1416
import java.util.UUID;
@@ -17,7 +19,9 @@
1719
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
1820

1921
public class Instrumentation {
20-
private static void tracing(KurrentDBClient client) throws ExecutionException, InterruptedException {
22+
private static void tracing(KurrentDBClient client) throws ExecutionException, InterruptedException, JsonProcessingException {
23+
ObjectMapper objectMapper = new ObjectMapper();
24+
2125
Resource resource = Resource.getDefault().toBuilder()
2226
.put(SERVICE_NAME, "sample")
2327
.build();
@@ -47,10 +51,7 @@ private static void tracing(KurrentDBClient client) throws ExecutionException, I
4751
.builderAsJson(
4852
UUID.randomUUID(),
4953
"some-event",
50-
new TestEvent(
51-
"1",
52-
"some value"
53-
))
54+
objectMapper.writeValueAsBytes(new TestEvent("1", "some value")))
5455
.build();
5556
// endregion setup-client-for-tracing
5657

src/test/java/io/kurrent/dbclient/streams/MetadataTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ default void testSetStreamMetadata() throws Throwable {
2727

2828
metadata.setAcl(acl);
2929

30-
HashMap<String, Object> payload = new HashMap<>();
30+
byte[] payload = "data".getBytes();
3131

3232
String streamName = generateName();
3333

@@ -43,7 +43,7 @@ default void testSetStreamMetadata() throws Throwable {
4343
default void testReadNoExistingMetadata() throws Throwable {
4444
KurrentDBClient client = getDatabase().defaultClient();
4545
String streamName = generateName();
46-
client.appendToStream(streamName, EventDataBuilder.json("bar", new HashMap<String, Object>()).build()).get();
46+
client.appendToStream(streamName, EventDataBuilder.json("bar", "data".getBytes()).build()).get();
4747

4848
StreamMetadata got = client.getStreamMetadata(streamName).get();
4949

@@ -54,7 +54,7 @@ default void testReadNoExistingMetadata() throws Throwable {
5454
default void testReadMetadataAfterStreamDeletion() throws Throwable {
5555
KurrentDBClient client = getDatabase().defaultClient();
5656
String streamName = generateName();
57-
client.appendToStream(streamName, EventDataBuilder.json("bar", new HashMap<String, Object>()).build()).get();
57+
client.appendToStream(streamName, EventDataBuilder.json("bar", "data".getBytes()).build()).get();
5858

5959
client.deleteStream(streamName).get();
6060
client.getStreamMetadata(streamName).get();

0 commit comments

Comments
 (0)