20
20
package com .metamx .tranquility .test
21
21
22
22
import com .fasterxml .jackson .databind
23
- import com .fasterxml .jackson .databind .DeserializationContext
24
- import com .fasterxml .jackson .databind .InjectableValues
25
- import com .fasterxml .jackson .databind .ObjectMapper
23
+ import com .fasterxml .jackson .databind .{ObjectReader , DeserializationContext , InjectableValues , ObjectMapper }
26
24
import com .google .inject .Key
27
25
import com .metamx .common .Granularity
28
26
import com .metamx .common .scala .untyped .Dict
29
- import com .metamx .emitter .core .Emitter
30
- import com .metamx .emitter .core .Event
27
+ import com .metamx .emitter .core .NoopEmitter
31
28
import com .metamx .emitter .service .ServiceEmitter
32
29
import com .metamx .tranquility .beam .ClusteredBeamTuning
33
30
import com .metamx .tranquility .druid .DruidBeamConfig
@@ -56,6 +53,30 @@ import _root_.scala.collection.JavaConverters._
56
53
57
54
class DruidBeamTest extends FunSuite with Matchers
58
55
{
56
+ private def emptyEmitter (): ServiceEmitter = new ServiceEmitter (
57
+ " service" , " host" , new NoopEmitter ()
58
+ )
59
+
60
+ private def defaultObjectReader (): ObjectReader = DruidGuicer .Default .objectMapper.reader(
61
+ new InjectableValues
62
+ {
63
+ override def findInjectableValue (
64
+ valueId : Any ,
65
+ ctxt : DeserializationContext ,
66
+ forProperty : databind.BeanProperty ,
67
+ beanInstance : scala.Any
68
+ ): AnyRef =
69
+ {
70
+ valueId match {
71
+ case k : Key [_] if k.getTypeLiteral.getRawType == classOf [ChatHandlerProvider ] => new NoopChatHandlerProvider
72
+ case k : Key [_] if k.getTypeLiteral.getRawType == classOf [ObjectMapper ] => DruidGuicer .Default .objectMapper
73
+ case k : Key [_] if k.getTypeLiteral.getRawType == classOf [EventReceiverFirehoseRegister ] =>
74
+ new EventReceiverFirehoseRegister
75
+ }
76
+ }
77
+ }
78
+ ).withType(classOf [Task ])
79
+
59
80
test(" GenerateAvailabilityGroup" ) {
60
81
val dt = new DateTime (" 2010-02-03T04:34:56.789" , DateTimeZone .forID(" America/Los_Angeles" ))
61
82
assert(DruidBeamMaker .generateAvailabilityGroup(" x" , dt, 1 ) === " x-2010-02-03T12:34:56.789Z-0001" )
@@ -123,23 +144,13 @@ class DruidBeamTest extends FunSuite with Matchers
123
144
DruidRollup (
124
145
dimensions = SpecificDruidDimensions (Seq (" dim1" , " dim2" ), Seq (DruidSpatialDimension .singleField(" spatial1" ))),
125
146
aggregators = Seq (new LongSumAggregatorFactory (" met1" , " met1" )),
126
- indexGranularity = QueryGranularities .MINUTE
147
+ indexGranularity = QueryGranularities .MINUTE ,
148
+ true
127
149
),
128
150
new TimestampSpec (" ts" , " iso" , null ),
129
151
null ,
130
152
null ,
131
- new ServiceEmitter (
132
- " service" , " host" , new Emitter
133
- {
134
- override def flush (): Unit = ???
135
-
136
- override def emit (event : Event ): Unit = ???
137
-
138
- override def close (): Unit = ???
139
-
140
- override def start (): Unit = ???
141
- }
142
- ),
153
+ emptyEmitter(),
143
154
null ,
144
155
DruidGuicer .Default .objectMapper
145
156
)
@@ -151,27 +162,7 @@ class DruidBeamTest extends FunSuite with Matchers
151
162
1 ,
152
163
2
153
164
)
154
- val objectReader = DruidGuicer .Default .objectMapper.reader(
155
- new InjectableValues
156
- {
157
- override def findInjectableValue (
158
- valueId : Any ,
159
- ctxt : DeserializationContext ,
160
- forProperty : databind.BeanProperty ,
161
- beanInstance : scala.Any
162
- ): AnyRef =
163
- {
164
- valueId match {
165
- case k : Key [_] if k.getTypeLiteral.getRawType == classOf [ChatHandlerProvider ] => new NoopChatHandlerProvider
166
- case k : Key [_] if k.getTypeLiteral.getRawType == classOf [ObjectMapper ] => DruidGuicer .Default .objectMapper
167
- case k : Key [_] if k.getTypeLiteral.getRawType == classOf [EventReceiverFirehoseRegister ] =>
168
- new EventReceiverFirehoseRegister
169
- }
170
- }
171
- }
172
- ).withType(classOf [Task ])
173
-
174
- val task = objectReader.readValue(taskBytes).asInstanceOf [RealtimeIndexTask ]
165
+ val task = defaultObjectReader().readValue(taskBytes).asInstanceOf [RealtimeIndexTask ]
175
166
task.getId should be(" index_realtime_mydatasource_2000-01-01T00:00:00.000Z_1_2" )
176
167
task.getDataSource should be(" mydatasource" )
177
168
task.getTaskResource.getAvailabilityGroup should be(" mygroup" )
@@ -202,4 +193,39 @@ class DruidBeamTest extends FunSuite with Matchers
202
193
parseSpec.getDimensionsSpec.getDimensions.asScala.map(_.getName) should be(Seq (" dim1" , " dim2" , " spatial1" ))
203
194
parseSpec.getDimensionsSpec.getSpatialDimensions.asScala.map(_.getDimName) should be(Seq (" spatial1" ))
204
195
}
196
+
197
+ test(" Attribute isRollup should be passed to task" ) {
198
+ val isRollup = false
199
+ val druidBeamMaker = new DruidBeamMaker [Dict ](
200
+ DruidBeamConfig (),
201
+ DruidLocation .create(" druid/overlord" , " mydatasource" ),
202
+ ClusteredBeamTuning (),
203
+ DruidTuning ().toMap,
204
+ DruidRollup (
205
+ dimensions = SpecificDruidDimensions (Seq (), Seq ()),
206
+ aggregators = Seq (),
207
+ indexGranularity = QueryGranularities .NONE ,
208
+ // isRollup is set for test.
209
+ isRollup
210
+ ),
211
+ new TimestampSpec (" ts" , " iso" , null ),
212
+ null ,
213
+ null ,
214
+ emptyEmitter(),
215
+ null ,
216
+ DruidGuicer .Default .objectMapper
217
+ )
218
+
219
+ val interval = new Interval (" 2000/PT1H" , ISOChronology .getInstanceUTC)
220
+ val taskBytes = druidBeamMaker.taskBytes(
221
+ interval,
222
+ " mygroup" ,
223
+ " myfirehose" ,
224
+ 1 ,
225
+ 2
226
+ )
227
+ val task = defaultObjectReader().readValue(taskBytes).asInstanceOf [RealtimeIndexTask ]
228
+
229
+ task.getRealtimeIngestionSchema.getDataSchema.getGranularitySpec.isRollup should be(isRollup)
230
+ }
205
231
}
0 commit comments