Skip to content
Closed
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions sdk/src/androidTest/java/com/mapbox/maps/MapIntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.mapbox.maps.extension.style.sources.getSourceAs
import com.mapbox.maps.extension.style.style
import org.junit.After
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
Expand All @@ -34,6 +36,25 @@ class MapIntegrationTest {
private lateinit var mapboxMap: MapboxMap
private lateinit var countDownLatch: CountDownLatch

private val pointCount = 10000

private fun createRandomPoint(): Point {
val random = Random()
return Point.fromLngLat(
random.nextDouble() * -360.0 + 180.0,
random.nextDouble() * -180.0 + 90.0
)
}

private fun getFeatureCollection(): FeatureCollection {
val pointList = mutableListOf<Feature>()
for (i in 0..pointCount) {
val point = createRandomPoint()
pointList.add(Feature.fromGeometry(point))
}
return FeatureCollection.fromFeatures(pointList)
}

@Before
@UiThreadTest
fun setUp() {
Expand Down Expand Up @@ -480,6 +501,40 @@ class MapIntegrationTest {
}
}

@Test
fun testApplyLargeDataAfterCreate() {
countDownLatch = CountDownLatch(1)
rule.scenario.onActivity {
mapView = MapView(it)
mapboxMap = mapView.getMapboxMap()
it.frameLayout.addView(mapView)
mapboxMap.setCamera(
CameraOptions.Builder()
.center(Point.fromLngLat(0.0, 0.0))
.zoom(9.0)
.build()
)
mapboxMap.loadStyleUri(Style.MAPBOX_STREETS) {
val source = geoJsonSource("source") {
geometry(Point.fromLngLat(0.0, 0.0))
}
// Set a large data async
source.featureCollection(getFeatureCollection()) {
fail("This callback should not be invoked")
}
// change geometry immediately, this should cancel the last large data update
source.geometry(Point.fromLngLat(0.0, 0.0))
// Set a large data async, this should update correctly.
source.featureCollection(getFeatureCollection()) {
countDownLatch.countDown()
}
}
}
if (!countDownLatch.await(10, TimeUnit.SECONDS)) {
throw TimeoutException()
}
}

@After
@UiThreadTest
fun teardown() {
Expand Down