Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing flush API (close #679) #684

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.snowplowanalytics.snowplow.tracker.integration

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.snowplowanalytics.snowplow.Snowplow
import com.snowplowanalytics.snowplow.configuration.EmitterConfiguration
import com.snowplowanalytics.snowplow.configuration.NetworkConfiguration
import com.snowplowanalytics.snowplow.emitter.BufferOption
import com.snowplowanalytics.snowplow.event.ScreenView
import com.snowplowanalytics.snowplow.network.HttpMethod
import com.snowplowanalytics.snowplow.tracker.MockNetworkConnection
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FlushTest {

@Test
fun testFlushEventsViaTracker() {
val networkConnection = MockNetworkConnection(HttpMethod.GET, 200)
val networkConfig = NetworkConfiguration(networkConnection)
val emitterConfig = EmitterConfiguration().bufferOption(BufferOption.SmallGroup)

val tracker = Snowplow.createTracker(
InstrumentationRegistry.getInstrumentation().targetContext,
"flush" + Math.random().toString(),
networkConfig,
emitterConfig
)

tracker.track(ScreenView("screenName"))
Thread.sleep(200)
Assert.assertEquals(0, networkConnection.countRequests())

tracker.emitter.flush()

var counter = 0
while (networkConnection.countRequests() == 0) {
Thread.sleep(500)
counter++
if (counter > 10) {
return
}
}

Assert.assertEquals(1, networkConnection.countRequests())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class EmitterControllerImpl(serviceProvider: ServiceProviderInterface) :
emitter.resumeEmit()
}

override fun flush() {
emitter.flush()
}

// Private methods
private val dirtyConfig: EmitterConfiguration
get() = serviceProvider.emitterConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ interface EmitterController : EmitterConfigurationInterface {
* The emitter will resume emitting events again.
*/
fun resume()

/**
* Flush all stored events.
*/
fun flush()
}
Loading