@@ -35,24 +35,28 @@ import org.apache.spark.streaming.util.ManualClock
3535import org .apache .spark .streaming .{TestSuiteBase , TestOutputStream , StreamingContext }
3636import org .apache .spark .streaming .flume .sink ._
3737
38- class FlumePollingStreamSuite extends TestSuiteBase {
38+ class FlumePollingStreamSuite extends TestSuiteBase {
3939
4040 val testPort = 9999
41+ val batchCount = 5
42+ val eventsPerBatch = 100
43+ val totalEventsPerChannel = batchCount * eventsPerBatch
44+ val channelCapacity = 5000
4145
4246 test(" flume polling test" ) {
4347 // Set up the streaming context and input streams
4448 val ssc = new StreamingContext (conf, batchDuration)
4549 val flumeStream : ReceiverInputDStream [SparkFlumeEvent ] =
4650 FlumeUtils .createPollingStream(ssc, Seq (new InetSocketAddress (" localhost" , testPort)),
47- StorageLevel .MEMORY_AND_DISK , 100 , 1 )
51+ StorageLevel .MEMORY_AND_DISK , eventsPerBatch , 1 )
4852 val outputBuffer = new ArrayBuffer [Seq [SparkFlumeEvent ]]
4953 with SynchronizedBuffer [Seq [SparkFlumeEvent ]]
5054 val outputStream = new TestOutputStream (flumeStream, outputBuffer)
5155 outputStream.register()
5256
5357 // Start the channel and sink.
5458 val context = new Context ()
55- context.put(" capacity" , " 5000 " )
59+ context.put(" capacity" , channelCapacity.toString )
5660 context.put(" transactionCapacity" , " 1000" )
5761 context.put(" keep-alive" , " 0" )
5862 val channel = new MemoryChannel ()
@@ -77,15 +81,16 @@ import org.apache.spark.streaming.flume.sink._
7781 val ssc = new StreamingContext (conf, batchDuration)
7882 val addresses = Seq (testPort, testPort + 1 ).map(new InetSocketAddress (" localhost" , _))
7983 val flumeStream : ReceiverInputDStream [SparkFlumeEvent ] =
80- FlumeUtils .createPollingStream(ssc, addresses, StorageLevel .MEMORY_AND_DISK , 100 , 5 )
84+ FlumeUtils .createPollingStream(ssc, addresses, StorageLevel .MEMORY_AND_DISK ,
85+ eventsPerBatch, 5 )
8186 val outputBuffer = new ArrayBuffer [Seq [SparkFlumeEvent ]]
8287 with SynchronizedBuffer [Seq [SparkFlumeEvent ]]
8388 val outputStream = new TestOutputStream (flumeStream, outputBuffer)
8489 outputStream.register()
8590
8691 // Start the channel and sink.
8792 val context = new Context ()
88- context.put(" capacity" , " 5000 " )
93+ context.put(" capacity" , channelCapacity.toString )
8994 context.put(" transactionCapacity" , " 1000" )
9095 context.put(" keep-alive" , " 0" )
9196 val channel = new MemoryChannel ()
@@ -127,7 +132,7 @@ import org.apache.spark.streaming.flume.sink._
127132 executorCompletion.take()
128133 }
129134 val startTime = System .currentTimeMillis()
130- while (outputBuffer.size < 5 &&
135+ while (outputBuffer.size < batchCount * channels.size &&
131136 System .currentTimeMillis() - startTime < 15000 ) {
132137 logInfo(" output.size = " + outputBuffer.size)
133138 Thread .sleep(100 )
@@ -138,9 +143,9 @@ import org.apache.spark.streaming.flume.sink._
138143 ssc.stop()
139144
140145 val flattenedBuffer = outputBuffer.flatten
141- assert(flattenedBuffer.size === 25 * channels.size)
146+ assert(flattenedBuffer.size === totalEventsPerChannel * channels.size)
142147 var counter = 0
143- for (k <- 0 until channels.size; i <- 0 until 25 ) {
148+ for (k <- 0 until channels.size; i <- 0 until totalEventsPerChannel ) {
144149 val eventToVerify = EventBuilder .withBody((channels(k).getName + " - " +
145150 String .valueOf(i)).getBytes(" utf-8" ),
146151 Map [String , String ](" test-" + i.toString -> " header" ))
@@ -157,7 +162,7 @@ import org.apache.spark.streaming.flume.sink._
157162 j += 1
158163 }
159164 }
160- assert(counter === 25 * channels.size)
165+ assert(counter === totalEventsPerChannel * channels.size)
161166 }
162167
163168 def assertChannelIsEmpty (channel : MemoryChannel ) = {
@@ -170,10 +175,10 @@ import org.apache.spark.streaming.flume.sink._
170175 private class TxnSubmitter (channel : MemoryChannel , clock : ManualClock ) extends Callable [Void ] {
171176 override def call (): Void = {
172177 var t = 0
173- for (i <- 0 until 5 ) {
178+ for (i <- 0 until batchCount ) {
174179 val tx = channel.getTransaction
175180 tx.begin()
176- for (j <- 0 until 5 ) {
181+ for (j <- 0 until eventsPerBatch ) {
177182 channel.put(EventBuilder .withBody((channel.getName + " - " + String .valueOf(t)).getBytes(
178183 " utf-8" ),
179184 Map [String , String ](" test-" + t.toString -> " header" )))
0 commit comments