@@ -7,7 +7,7 @@ import java.util.concurrent.atomic.AtomicBoolean
7
7
import com .github .mmolimar .ksql .jdbc .KsqlEntityHeaders ._
8
8
import com .github .mmolimar .ksql .jdbc .embedded .{EmbeddedKafkaCluster , EmbeddedKsqlEngine , EmbeddedZookeeperServer }
9
9
import com .github .mmolimar .ksql .jdbc .utils .TestUtils
10
- import org .apache .kafka .clients .producer .ProducerRecord
10
+ import org .apache .kafka .clients .producer .{ KafkaProducer , ProducerRecord }
11
11
import org .scalatest ._
12
12
13
13
class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAfterAll {
@@ -16,14 +16,14 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
16
16
val kafkaCluster = new EmbeddedKafkaCluster (zkServer.getConnection)
17
17
val ksqlEngine = new EmbeddedKsqlEngine (kafkaCluster.getBrokerList)
18
18
19
- lazy val kafkaProducer = TestUtils .buildProducer(kafkaCluster.getBrokerList)
19
+ lazy val kafkaProducer : KafkaProducer [ Array [ Byte ], Array [ Byte ]] = TestUtils .buildProducer(kafkaCluster.getBrokerList)
20
20
21
21
val ksqlUrl = s " jdbc:ksql://localhost: ${ksqlEngine.getPort}?timeout=20000 "
22
22
var ksqlConnection : Connection = _
23
- val topic = TestUtils .randomString()
23
+ val topic : String = TestUtils .randomString()
24
24
25
25
val stop = new AtomicBoolean (false )
26
- val producerThread = new BackgroundOps (stop, () => produceMessages)
26
+ val producerThread = new BackgroundOps (stop, () => produceMessages() )
27
27
28
28
" A KsqlConnection" when {
29
29
@@ -35,24 +35,24 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
35
35
" create the table properly" in {
36
36
val resultSet = createTestTableOrStream(table)
37
37
resultSet.next should be(true )
38
- resultSet.getString(commandStatusEntity( 0 ) .name) should be(" TABLE" )
38
+ resultSet.getString(commandStatusEntity.head .name) should be(" TABLE" )
39
39
resultSet.getString(commandStatusEntity(1 ).name) should be(table.toUpperCase)
40
40
resultSet.getString(commandStatusEntity(2 ).name) should be(" CREATE" )
41
41
resultSet.getString(commandStatusEntity(3 ).name) should be(" SUCCESS" )
42
42
resultSet.getString(commandStatusEntity(4 ).name) should be(" Table created" )
43
43
resultSet.next should be(false )
44
- resultSet.close
44
+ resultSet.close()
45
45
}
46
46
47
47
" list the table already created" in {
48
48
val resultSet = ksqlConnection.createStatement.executeQuery(s " SHOW TABLES " )
49
49
resultSet.next should be(true )
50
- resultSet.getString(tablesListEntity( 0 ) .name) should be(table.toUpperCase)
50
+ resultSet.getString(tablesListEntity.head .name) should be(table.toUpperCase)
51
51
resultSet.getString(tablesListEntity(1 ).name) should be(topic)
52
52
resultSet.getString(tablesListEntity(2 ).name) should be(" JSON" )
53
53
resultSet.getBoolean(tablesListEntity(3 ).name) should be(false )
54
54
resultSet.next should be(false )
55
- resultSet.close
55
+ resultSet.close()
56
56
}
57
57
58
58
" be able to get the execution plan for a query in a table" in {
@@ -61,17 +61,19 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
61
61
resultSet.getString(queryDescriptionEntity(1 ).name) should be(" ROWTIME, ROWKEY, FIELD1, FIELD2, FIELD3" )
62
62
resultSet.getString(queryDescriptionEntity(2 ).name) should be(table.toUpperCase)
63
63
resultSet.next should be(false )
64
- resultSet.close
64
+ resultSet.close()
65
65
}
66
66
67
67
" be able to query all fields in the table" in {
68
68
var counter = 0
69
69
val statement = ksqlConnection.createStatement
70
70
statement.setMaxRows(maxRecords)
71
+ statement.getMoreResults(1 ) should be(false )
71
72
val resultSet = statement.executeQuery(s " SELECT * FROM $table" )
73
+ statement.getMoreResults(1 ) should be(true )
72
74
while (resultSet.next) {
73
75
resultSet.getLong(1 ) should not be (- 1 )
74
- Option (resultSet.getString(2 )) should not be ( None )
76
+ Option (resultSet.getString(2 )) should not be None
75
77
resultSet.getInt(3 ) should be(123 )
76
78
resultSet.getDouble(4 ) should be(45.4 )
77
79
resultSet.getString(5 ) should be(" lorem ipsum" )
@@ -81,9 +83,10 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
81
83
counter += 1
82
84
}
83
85
counter should be(maxRecords)
86
+ statement.getMoreResults() should be(false )
84
87
85
- resultSet.close
86
- statement.close
88
+ resultSet.close()
89
+ statement.close()
87
90
88
91
val metadata = resultSet.getMetaData
89
92
metadata.getColumnCount should be(5 )
@@ -168,19 +171,19 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
168
171
resultSet.getString(sourceDescriptionEntity(3 ).name) should be(" TABLE" )
169
172
resultSet.getString(sourceDescriptionEntity(4 ).name) should be(" JSON" )
170
173
resultSet.next should be(false )
171
- resultSet.close
174
+ resultSet.close()
172
175
}
173
176
174
177
" drop the table" in {
175
178
val resultSet = ksqlConnection.createStatement.executeQuery(s " DROP TABLE $table" )
176
179
resultSet.next should be(true )
177
- resultSet.getString(commandStatusEntity( 0 ) .name) should be(" TABLE" )
180
+ resultSet.getString(commandStatusEntity.head .name) should be(" TABLE" )
178
181
resultSet.getString(commandStatusEntity(1 ).name) should be(table.toUpperCase)
179
182
resultSet.getString(commandStatusEntity(2 ).name) should be(" DROP" )
180
183
resultSet.getString(commandStatusEntity(3 ).name) should be(" SUCCESS" )
181
- resultSet.getString(commandStatusEntity(4 ).name) should be(s " Source ${table.toUpperCase} was dropped. " )
184
+ resultSet.getString(commandStatusEntity(4 ).name) should be(s " Source ${table.toUpperCase} (topic: $topic ) was dropped." )
182
185
resultSet.next should be(false )
183
- resultSet.close
186
+ resultSet.close()
184
187
}
185
188
}
186
189
@@ -190,25 +193,25 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
190
193
val stream = TestUtils .randomString()
191
194
192
195
" create the stream properly" in {
193
- val resultSet = createTestTableOrStream(stream, true )
196
+ val resultSet = createTestTableOrStream(str = stream, isStream = true )
194
197
resultSet.next should be(true )
195
- resultSet.getString(commandStatusEntity( 0 ) .name) should be(" STREAM" )
198
+ resultSet.getString(commandStatusEntity.head .name) should be(" STREAM" )
196
199
resultSet.getString(commandStatusEntity(1 ).name) should be(stream.toUpperCase)
197
200
resultSet.getString(commandStatusEntity(2 ).name) should be(" CREATE" )
198
201
resultSet.getString(commandStatusEntity(3 ).name) should be(" SUCCESS" )
199
202
resultSet.getString(commandStatusEntity(4 ).name) should be(" Stream created" )
200
203
resultSet.next should be(false )
201
- resultSet.close
204
+ resultSet.close()
202
205
}
203
206
204
207
" list the stream already created" in {
205
208
val resultSet = ksqlConnection.createStatement.executeQuery(s " SHOW STREAMS " )
206
209
resultSet.next should be(true )
207
- resultSet.getString(streamsListEntity( 0 ) .name) should be(stream.toUpperCase)
210
+ resultSet.getString(streamsListEntity.head .name) should be(stream.toUpperCase)
208
211
resultSet.getString(streamsListEntity(1 ).name) should be(topic)
209
212
resultSet.getString(streamsListEntity(2 ).name) should be(" JSON" )
210
213
resultSet.next should be(false )
211
- resultSet.close
214
+ resultSet.close()
212
215
}
213
216
214
217
" be able to get the execution plan for a query in a stream" in {
@@ -217,17 +220,19 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
217
220
resultSet.getString(queryDescriptionEntity(1 ).name) should be(" ROWTIME, ROWKEY, FIELD1, FIELD2, FIELD3" )
218
221
resultSet.getString(queryDescriptionEntity(2 ).name) should be(stream.toUpperCase)
219
222
resultSet.next should be(false )
220
- resultSet.close
223
+ resultSet.close()
221
224
}
222
225
223
226
" be able to query all fields in the stream" in {
224
227
var counter = 0
225
228
val statement = ksqlConnection.createStatement
226
229
statement.setMaxRows(maxRecords)
230
+ statement.getMoreResults(1 ) should be(false )
227
231
val resultSet = statement.executeQuery(s " SELECT * FROM $stream" )
232
+ statement.getMoreResults(1 ) should be(true )
228
233
while (resultSet.next) {
229
234
resultSet.getLong(1 ) should not be (- 1 )
230
- Option (resultSet.getString(2 )) should not be ( None )
235
+ Option (resultSet.getString(2 )) should not be None
231
236
resultSet.getInt(3 ) should be(123 )
232
237
resultSet.getDouble(4 ) should be(45.4 )
233
238
resultSet.getString(5 ) should be(" lorem ipsum" )
@@ -237,9 +242,10 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
237
242
counter += 1
238
243
}
239
244
counter should be(maxRecords)
245
+ statement.getMoreResults(1 ) should be(false )
240
246
241
- resultSet.close
242
- statement.close
247
+ resultSet.close()
248
+ statement.close()
243
249
244
250
val metadata = resultSet.getMetaData
245
251
metadata.getColumnCount should be(5 )
@@ -323,19 +329,19 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
323
329
resultSet.getString(sourceDescriptionEntity(3 ).name) should be(" STREAM" )
324
330
resultSet.getString(sourceDescriptionEntity(4 ).name) should be(" JSON" )
325
331
resultSet.next should be(false )
326
- resultSet.close
332
+ resultSet.close()
327
333
}
328
334
329
335
" drop the stream" in {
330
336
val resultSet = ksqlConnection.createStatement.executeQuery(s " DROP STREAM $stream" )
331
337
resultSet.next should be(true )
332
- resultSet.getString(commandStatusEntity( 0 ) .name) should be(" STREAM" )
338
+ resultSet.getString(commandStatusEntity.head .name) should be(" STREAM" )
333
339
resultSet.getString(commandStatusEntity(1 ).name) should be(stream.toUpperCase)
334
340
resultSet.getString(commandStatusEntity(2 ).name) should be(" DROP" )
335
341
resultSet.getString(commandStatusEntity(3 ).name) should be(" SUCCESS" )
336
- resultSet.getString(commandStatusEntity(4 ).name) should be(s " Source ${stream.toUpperCase} was dropped. " )
342
+ resultSet.getString(commandStatusEntity(4 ).name) should be(s " Source ${stream.toUpperCase} (topic: $topic ) was dropped." )
337
343
resultSet.next should be(false )
338
- resultSet.close
344
+ resultSet.close()
339
345
}
340
346
}
341
347
@@ -344,19 +350,22 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
344
350
" show the content of that topic" in {
345
351
val statement = ksqlConnection.createStatement
346
352
statement.setMaxRows(3 )
353
+ statement.getMoreResults(1 ) should be(false )
347
354
val resultSet = statement.executeQuery(s " PRINT ' $topic' " )
355
+ statement.getMoreResults(1 ) should be(true )
348
356
resultSet.next should be(true )
349
- resultSet.getString(printTopic( 0 ) .name) should be(" Format:STRING" )
357
+ resultSet.getString(printTopic.head .name) should be(" Format:STRING" )
350
358
resultSet.next should be(true )
351
359
resultSet.next should be(true )
352
360
resultSet.next should be(false )
353
- resultSet.close
354
- statement.close
361
+ statement.getMoreResults() should be(false )
362
+ resultSet.close()
363
+ statement.close()
355
364
}
356
365
}
357
366
}
358
367
359
- private def produceMessages : Unit = {
368
+ private def produceMessages () : Unit = {
360
369
val key = TestUtils .randomString().getBytes
361
370
val value =
362
371
"""
@@ -378,53 +387,53 @@ class KsqlDriverIntegrationTest extends WordSpec with Matchers with BeforeAndAft
378
387
s " WITH (KAFKA_TOPIC=' $topic', VALUE_FORMAT='JSON', KEY='FIELD1'); " )
379
388
}
380
389
381
- override def beforeAll = {
382
- DriverManager .registerDriver(new KsqlDriver );
390
+ override def beforeAll () : Unit = {
391
+ DriverManager .registerDriver(new KsqlDriver )
383
392
384
- zkServer.startup
393
+ zkServer.startup()
385
394
TestUtils .waitTillAvailable(" localhost" , zkServer.getPort, 5000 )
386
395
387
- kafkaCluster.startup
396
+ kafkaCluster.startup()
388
397
kafkaCluster.getPorts.foreach { port =>
389
398
TestUtils .waitTillAvailable(" localhost" , port, 5000 )
390
399
}
391
400
392
401
kafkaCluster.createTopic(topic)
393
402
kafkaCluster.existTopic(topic) should be(true )
394
- producerThread.start
403
+ producerThread.start()
395
404
396
- ksqlEngine.startup
405
+ ksqlEngine.startup()
397
406
TestUtils .waitTillAvailable(" localhost" , ksqlEngine.getPort, 5000 )
398
407
399
408
ksqlConnection = DriverManager .getConnection(ksqlUrl)
400
409
401
410
}
402
411
403
- override def afterAll = {
412
+ override def afterAll () : Unit = {
404
413
info(s " Produced ${producerThread.getNumExecs} messages " )
405
414
stop.set(true )
406
- TestUtils .swallow(producerThread.interrupt)
415
+ TestUtils .swallow(producerThread.interrupt() )
407
416
408
- TestUtils .swallow(ksqlConnection.close)
409
- ksqlEngine.shutdown
410
- TestUtils .swallow(kafkaProducer.close)
417
+ TestUtils .swallow(ksqlConnection.close() )
418
+ ksqlEngine.shutdown()
419
+ TestUtils .swallow(kafkaProducer.close() )
411
420
412
- kafkaCluster.shutdown
413
- zkServer.shutdown
421
+ kafkaCluster.shutdown()
422
+ zkServer.shutdown()
414
423
}
415
424
416
425
}
417
426
418
427
class BackgroundOps (stop : AtomicBoolean , exec : () => Unit ) extends Thread {
419
428
private var count = 0L
420
429
421
- override def run = {
430
+ override def run () : Unit = {
422
431
while (! stop.get) {
423
432
exec()
424
433
this .count += 1
425
434
}
426
435
}
427
436
428
- def getNumExecs = this .count
437
+ def getNumExecs : Long = this .count
429
438
}
430
439
0 commit comments