-
Notifications
You must be signed in to change notification settings - Fork 26
/
PutGeoMesaKafkaTest.scala
75 lines (65 loc) · 3.02 KB
/
PutGeoMesaKafkaTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/***********************************************************************
* Copyright (c) 2015-2022 Commonwealth Computer Research, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at
* http://www.opensource.org/licenses/apache2.0.php.
***********************************************************************/
package org.geomesa.nifi.processors.kafka
import org.apache.nifi.util.{TestRunner, TestRunners}
import org.geomesa.nifi.datastore.processor.mixins.{ConvertInputProcessor, DataStoreProcessor, FeatureTypeProcessor}
import org.geomesa.nifi.datastore.processor.{PutGeoMesa, Relationships}
import org.geotools.data.DataStoreFinder
import org.junit.runner.RunWith
import org.locationtech.geomesa.kafka.KafkaContainerTest
import org.locationtech.geomesa.kafka.data.KafkaDataStoreParams
import org.locationtech.geomesa.utils.collection.SelfClosingIterator
import org.specs2.runner.JUnitRunner
@RunWith(classOf[JUnitRunner])
class PutGeoMesaKafkaTest extends KafkaContainerTest {
import scala.collection.JavaConverters._
sequential
lazy val dsParams = Map(
"kafka.brokers" -> brokers // note: zk-less usage
)
// we use class name to prevent spillage between unit tests
lazy val root = getClass.getSimpleName
def configureKafkaService(runner: TestRunner, catalog: String): Unit = {
val service = new KafkaDataStoreService()
runner.addControllerService("data-store", service)
dsParams.foreach { case (k, v) => runner.setProperty(service, k, v) }
runner.setProperty(service, KafkaDataStoreParams.Catalog.key, catalog)
runner.enableControllerService(service)
runner.setProperty(DataStoreProcessor.Properties.DataStoreService, "data-store")
}
"kafka processor" should {
"ingest using converters" in {
val catalog = s"${root}Ingest"
val runner = TestRunners.newTestRunner(new PutGeoMesa())
try {
configureKafkaService(runner, catalog)
runner.setProperty(FeatureTypeProcessor.Properties.SftNameKey, "example")
runner.setProperty(ConvertInputProcessor.Properties.ConverterNameKey, "example-csv")
runner.enqueue(getClass.getClassLoader.getResourceAsStream("example.csv"))
runner.run()
runner.assertTransferCount(Relationships.SuccessRelationship, 1)
runner.assertTransferCount(Relationships.FailureRelationship, 0)
} finally {
runner.shutdown()
}
val ds =
DataStoreFinder.getDataStore((dsParams ++
Map(KafkaDataStoreParams.Catalog.key -> catalog, KafkaDataStoreParams.ConsumerReadBack.key -> "Inf")).asJava)
ds must not(beNull)
try {
val sft = ds.getSchema("example")
sft must not(beNull)
val features = SelfClosingIterator(ds.getFeatureSource("example").getFeatures.features()).toList
logger.debug(features.mkString(";"))
features must haveLength(3)
} finally {
ds.dispose()
}
}
}
}