1
1
package io .kurrent .dbclient .samples .appending_events ;
2
2
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
3
4
import io .kurrent .dbclient .*;
4
5
import io .kurrent .dbclient .samples .TestEvent ;
5
6
6
7
import java .util .UUID ;
7
8
import java .util .concurrent .ExecutionException ;
8
9
10
+ import com .fasterxml .jackson .databind .ObjectMapper ;
11
+
12
+
9
13
public class AppendingEvents {
10
- private static void appendToStream (KurrentDBClient client ) throws ExecutionException , InterruptedException {
14
+ private static void appendToStream (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
11
15
// region append-to-stream
16
+ ObjectMapper objectMapper = new ObjectMapper ();
17
+
12
18
EventData eventData = EventData
13
19
.builderAsJson (
14
20
UUID .randomUUID (),
15
21
"some-event" ,
16
- new TestEvent (
17
- "1" ,
18
- "some value"
19
- ))
22
+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" ))
23
+ )
20
24
.build ();
21
25
22
26
AppendToStreamOptions options = AppendToStreamOptions .get ()
@@ -27,16 +31,15 @@ private static void appendToStream(KurrentDBClient client) throws ExecutionExcep
27
31
// endregion append-to-stream
28
32
}
29
33
30
- private static void appendWithSameId (KurrentDBClient client ) throws ExecutionException , InterruptedException {
34
+ private static void appendWithSameId (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
31
35
// region append-duplicate-event
36
+ ObjectMapper objectMapper = new ObjectMapper ();
37
+
32
38
EventData eventData = EventData
33
39
.builderAsJson (
34
40
UUID .randomUUID (),
35
41
"some-event" ,
36
- new TestEvent (
37
- "1" ,
38
- "some value"
39
- ))
42
+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" )))
40
43
.build ();
41
44
42
45
AppendToStreamOptions options = AppendToStreamOptions .get ()
@@ -51,26 +54,22 @@ private static void appendWithSameId(KurrentDBClient client) throws ExecutionExc
51
54
// endregion append-duplicate-event
52
55
}
53
56
54
- private static void appendWithNoStream (KurrentDBClient client ) throws ExecutionException , InterruptedException {
57
+ private static void appendWithNoStream (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
55
58
// region append-with-no-stream
59
+ ObjectMapper objectMapper = new ObjectMapper ();
60
+
56
61
EventData eventDataOne = EventData
57
62
.builderAsJson (
58
63
UUID .randomUUID (),
59
64
"some-event" ,
60
- new TestEvent (
61
- "1" ,
62
- "some value"
63
- ))
65
+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" )))
64
66
.build ();
65
67
66
68
EventData eventDataTwo = EventData
67
69
.builderAsJson (
68
70
UUID .randomUUID (),
69
71
"some-event" ,
70
- new TestEvent (
71
- "2" ,
72
- "some other value"
73
- ))
72
+ objectMapper .writeValueAsBytes (new TestEvent ("2" , "some other value" )))
74
73
.build ();
75
74
76
75
AppendToStreamOptions options = AppendToStreamOptions .get ()
@@ -85,8 +84,9 @@ private static void appendWithNoStream(KurrentDBClient client) throws ExecutionE
85
84
// endregion append-with-no-stream
86
85
}
87
86
88
- private static void appendWithConcurrencyCheck (KurrentDBClient client ) throws ExecutionException , InterruptedException {
87
+ private static void appendWithConcurrencyCheck (KurrentDBClient client ) throws ExecutionException , InterruptedException , JsonProcessingException {
89
88
// region append-with-concurrency-check
89
+ ObjectMapper objectMapper = new ObjectMapper ();
90
90
91
91
ReadStreamOptions readStreamOptions = ReadStreamOptions .get ()
92
92
.forwards ()
@@ -99,20 +99,14 @@ private static void appendWithConcurrencyCheck(KurrentDBClient client) throws Ex
99
99
.builderAsJson (
100
100
UUID .randomUUID (),
101
101
"some-event" ,
102
- new TestEvent (
103
- "1" ,
104
- "clientOne"
105
- ))
102
+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "clientOne" )))
106
103
.build ();
107
104
108
105
EventData clientTwoData = EventData
109
106
.builderAsJson (
110
107
UUID .randomUUID (),
111
108
"some-event" ,
112
- new TestEvent (
113
- "2" ,
114
- "clientTwo"
115
- ))
109
+ objectMapper .writeValueAsBytes (new TestEvent ("2" , "clientTwo" )))
116
110
.build ();
117
111
118
112
@@ -127,15 +121,14 @@ private static void appendWithConcurrencyCheck(KurrentDBClient client) throws Ex
127
121
// endregion append-with-concurrency-check
128
122
}
129
123
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
+
131
127
EventData eventData = EventData
132
128
.builderAsJson (
133
129
UUID .randomUUID (),
134
130
"some-event" ,
135
- new TestEvent (
136
- "1" ,
137
- "some value"
138
- ))
131
+ objectMapper .writeValueAsBytes (new TestEvent ("1" , "some value" )))
139
132
.build ();
140
133
//region overriding-user-credentials
141
134
UserCredentials credentials = new UserCredentials ("admin" , "changeit" );
0 commit comments