@@ -103,16 +103,67 @@ void sendSimpleMessage(VertxTestContext context) throws InterruptedException, Ex
103
103
}
104
104
105
105
@ Test
106
- void sendSimpleMessageToPartition (VertxTestContext context ) throws InterruptedException , ExecutionException {
107
- KafkaFuture <Void > future = adminClientFacade .createTopic (topic , 2 , 1 );
106
+ void sendMessagesToMultiplePartitions (VertxTestContext context ) throws InterruptedException , ExecutionException {
107
+ KafkaFuture <Void > future = adminClientFacade .createTopic (topic , 3 , 1 );
108
108
109
109
String value = "message-value" ;
110
- int partition = 1 ;
111
110
112
111
JsonArray records = new JsonArray ();
112
+ records .add (valuePartitionRecord (value , 0 ));
113
+
114
+ records .add (valuePartitionRecord (value , 1 ));
115
+
116
+ records .add (valuePartitionRecord (value , 2 ));
117
+
118
+ JsonObject root = new JsonObject ();
119
+ root .put ("records" , records );
120
+ System .out .println (root );
121
+
122
+ future .get ();
123
+
124
+ producerService ()
125
+ .sendRecordsRequest (topic , root , BridgeContentType .KAFKA_JSON_JSON )
126
+ .sendJsonObject (root , ar ->
127
+ context .verify (() -> {
128
+ assertThat (ar .succeeded (), is (true ));
129
+ HttpResponse <JsonObject > response = ar .result ();
130
+ assertThat (response .statusCode (), is (HttpResponseStatus .OK .code ()));
131
+ JsonObject bridgeResponse = response .body ();
132
+ System .out .println (bridgeResponse );
133
+ JsonArray offsets = bridgeResponse .getJsonArray ("offsets" );
134
+ assertThat (offsets .size (), is (3 ));
135
+ JsonObject metadata = offsets .getJsonObject (0 );
136
+ assertThat (metadata .getInteger ("partition" ), is (0 ));
137
+ assertThat (metadata .getLong ("offset" ), is (0L ));
138
+
139
+ JsonObject metadata2 = offsets .getJsonObject (1 );
140
+ assertThat (metadata2 .getInteger ("partition" ), is (1 ));
141
+ assertThat (metadata2 .getLong ("offset" ), is (0L ));
142
+
143
+ JsonObject metadata3 = offsets .getJsonObject (2 );
144
+ assertThat (metadata3 .getInteger ("partition" ), is (2 ));
145
+ assertThat (metadata3 .getLong ("offset" ), is (0L ));
146
+ context .completeNow ();
147
+ }));
148
+ assertThat (context .awaitCompletion (TEST_TIMEOUT , TimeUnit .SECONDS ), is (true ));
149
+ }
150
+
151
+ private static JsonObject valuePartitionRecord (String value , int partition ) {
113
152
JsonObject json = new JsonObject ();
114
153
json .put ("value" , value );
115
154
json .put ("partition" , partition );
155
+ return json ;
156
+ }
157
+
158
+ @ Test
159
+ void sendSimpleMessageToPartition (VertxTestContext context ) throws InterruptedException , ExecutionException {
160
+ KafkaFuture <Void > future = adminClientFacade .createTopic (topic , 2 , 1 );
161
+
162
+ String value = "message-value" ;
163
+ int partition = 1 ;
164
+
165
+ JsonArray records = new JsonArray ();
166
+ JsonObject json = valuePartitionRecord (value , partition );
116
167
records .add (json );
117
168
118
169
JsonObject root = new JsonObject ();
@@ -782,9 +833,7 @@ void sendToNonExistingPartitionsTest(VertxTestContext context) throws Interrupte
782
833
int partition = 1000 ;
783
834
784
835
JsonArray records = new JsonArray ();
785
- JsonObject json = new JsonObject ();
786
- json .put ("value" , value );
787
- json .put ("partition" , partition );
836
+ JsonObject json = valuePartitionRecord (value , partition );
788
837
records .add (json );
789
838
790
839
JsonObject root = new JsonObject ();
@@ -824,9 +873,7 @@ void sendToNonExistingTopicTest(VertxTestContext context) {
824
873
int partition = 1 ;
825
874
826
875
JsonArray records = new JsonArray ();
827
- JsonObject json = new JsonObject ();
828
- json .put ("value" , value );
829
- json .put ("partition" , partition );
876
+ JsonObject json = valuePartitionRecord (value , partition );
830
877
records .add (json );
831
878
832
879
JsonObject root = new JsonObject ();
@@ -1020,14 +1067,10 @@ void sendMultipleRecordsWithOneInvalidPartitionTest(VertxTestContext context) th
1020
1067
int partition = 1 ;
1021
1068
1022
1069
JsonArray records = new JsonArray ();
1023
- JsonObject json = new JsonObject ();
1024
- json .put ("value" , value );
1025
- json .put ("partition" , partition );
1070
+ JsonObject json = valuePartitionRecord (value , partition );
1026
1071
records .add (json );
1027
1072
1028
- JsonObject json2 = new JsonObject ();
1029
- json2 .put ("value" , value + "invalid" );
1030
- json2 .put ("partition" , 500 );
1073
+ JsonObject json2 = valuePartitionRecord (value + "invalid" , 500 );
1031
1074
records .add (json2 );
1032
1075
1033
1076
JsonObject root = new JsonObject ();
0 commit comments