-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- xamarin4.21.0
- xamarin4.18.0
- xamarin4.17.0
- v5.1.0
- v5.0.2
- v5.0.1
- v5.0.0
- v5.0.0-beta1
- v4.38.5
- v4.38.4
- v4.38.3
- v4.38.2
- v4.38.1
- v4.38.0
- v4.37.1
- v4.37.0
- v4.36.0
- v4.35.1
- v4.35.0
- v4.34.0
- v4.33.5
- v4.33.4
- v4.33.3
- v4.33.2
- v4.33.1
- v4.33.0
- v4.32.0
- v4.31.1
- v4.31.0
- v4.30.1
- v4.30.0
- v4.29.1
- v4.29.0
- v4.28.9
- v4.28.8
- v4.28.7
- v4.28.6
- v4.28.5
- v4.28.4
- v4.28.3
- v4.28.2
- v4.28.1
- v4.28.0
- v4.27.0
- v4.26.2
- v4.26.1
- v4.26.0
- v4.25.0
- v4.24.1
- v4.24.0
- v4.23.0
- v4.22.0
- v4.21.2
- v4.21.1
- v4.21.0
- v4.20.0
- v4.19.1
- v4.19.0
- v4.18.4
- v4.18.3
- v4.18.2
- v4.18.1
- v4.18.0
- v4.17.0
- v4.16.0
- unity4.20.1
- unity4.20.0
- unity4.19.2
- unity4.19.1
- unity4.19.0
- unity4.18.2
- unity4.18.1
- unity4.17.1
- unity4.17.0
- titanium4.17.0
- react_native4.18.2
- react_native4.18.1
- react_native4.18.0
- react_native4.17.2
- react_native4.17.1
- react_native4.17.0
- flutter4.17.1
- corona4.21.0
- corona4.20.0
- corona4.18.0
- corona4.17.0
- cordova4.21.0
- cordova4.18.0
- cordova4.17.1
- cordova4.17.0
- cocos2d-x4.18.0
- cocos2d-x4.17.1
- cocos2d-x4.17.0
- adobe_air4.18.0
- adobe_air4.17.2
- adobe_air4.17.1
- adobe_air4.17.0
Showing
1 changed file
with
87 additions
and
14 deletions.
There are no files selected for viewing
101 changes: 87 additions & 14 deletions
101
Adjust/test-kotlin/src/test/java/com/adjust/sdk/test/SchedulerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,105 @@ | ||
package com.adjust.sdk.test | ||
|
||
import com.adjust.sdk.scheduler.SingleThreadCachedScheduler | ||
import com.adjust.sdk.scheduler.* | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import java.lang.Thread.sleep | ||
import java.util.concurrent.TimeUnit | ||
|
||
class SchedulerTest { | ||
@Test | ||
fun stcs_submits_inOrder() { | ||
val ts = SingleThreadCachedScheduler("s") | ||
fun threadExecutor_submitsVarious_executesInOrder() { | ||
val threadExecutor: ThreadExecutor = SingleThreadCachedScheduler("s") | ||
var s = ""; | ||
ts.submit { s += "a" } | ||
ts.submit { s += "b" } | ||
ts.submit { s += "c" } | ||
threadExecutor.submit { s += "a" } | ||
threadExecutor.submit { s += "b" } | ||
threadExecutor.submit { s += "c" } | ||
Thread.sleep(1000) | ||
Assert.assertEquals("abc", s) | ||
} | ||
|
||
@Test | ||
fun stcs_schedules_inOrder() { | ||
val ts = SingleThreadCachedScheduler("s") | ||
fun threadScheduler_schedulesVariousDelayed_executesInDelayedOrder() { | ||
val threadScheduler: ThreadScheduler = SingleThreadCachedScheduler("s") | ||
var s = ""; | ||
ts.submit { s += "a" } | ||
ts.schedule ({ s += "e"}, 500) | ||
ts.submit { s += "b" } | ||
ts.schedule ({ s += "d"}, 250) | ||
ts.submit { s += "c" } | ||
threadScheduler.submit { s += "a" } | ||
threadScheduler.schedule ({ s += "e"}, 500) | ||
threadScheduler.submit { s += "b" } | ||
threadScheduler.schedule ({ s += "d"}, 250) | ||
threadScheduler.submit { s += "c" } | ||
Thread.sleep(1000) | ||
Assert.assertEquals("abcde", s) | ||
} | ||
|
||
@Test | ||
fun futureScheduler_ScheduleAndWaitWithKeepAlive() { | ||
// arrange | ||
val futureScheduler: FutureScheduler = SingleThreadFutureScheduler("s", true) | ||
|
||
// act | ||
var s = ""; | ||
val scheduledFuture = futureScheduler.scheduleFuture({ s += "a" }, 500) | ||
|
||
val withDelay = scheduledFuture.getDelay(TimeUnit.MILLISECONDS) | ||
val isNotDone = scheduledFuture.isDone | ||
val isNotCanceledBefore = scheduledFuture.isCancelled | ||
// wait for finish | ||
scheduledFuture.get() | ||
|
||
val noDelay = scheduledFuture.getDelay(TimeUnit.MILLISECONDS) | ||
val isDone = scheduledFuture.isDone | ||
val isNotCanceledBeforeAfter = scheduledFuture.isCancelled | ||
|
||
// assert | ||
// before finish | ||
Assert.assertTrue(withDelay > 0L) | ||
Assert.assertTrue(withDelay < 500L) | ||
Assert.assertTrue(noDelay <= 0L) | ||
Assert.assertFalse(isNotDone) | ||
|
||
// after finish | ||
Assert.assertEquals("a", s) | ||
Assert.assertTrue(isDone) | ||
Assert.assertFalse(isNotCanceledBefore) | ||
Assert.assertFalse(isNotCanceledBeforeAfter) | ||
} | ||
|
||
@Test | ||
fun futureScheduler_ScheduleAndCancelWithKeepAlive() { | ||
// arrange | ||
val futureScheduler: FutureScheduler = SingleThreadFutureScheduler("s", true) | ||
|
||
// act | ||
var s = ""; | ||
val scheduledFuture = futureScheduler.scheduleFuture({ s += "a" }, 500) | ||
|
||
// cancel | ||
scheduledFuture.cancel(false) | ||
|
||
val isDone = scheduledFuture.isDone | ||
val isCancelled = scheduledFuture.isCancelled | ||
|
||
// assert | ||
Assert.assertEquals("", s) | ||
Assert.assertTrue(isDone) | ||
Assert.assertTrue(isCancelled) | ||
} | ||
|
||
@Test | ||
fun futureScheduler_ScheduleWithFixedDelayWithKeepAlive() { | ||
// arrange | ||
val futureScheduler: FutureScheduler = SingleThreadFutureScheduler("s", true) | ||
|
||
// act | ||
var s = ""; | ||
val scheduledFuture = futureScheduler.scheduleFutureWithFixedDelay({ s += "a" }, 500, 500) | ||
|
||
Thread.sleep(650) | ||
val s1 = s | ||
Thread.sleep(650) | ||
|
||
// assert | ||
Assert.assertEquals("a", s1) | ||
Assert.assertEquals("aa", s) | ||
} | ||
|
||
} |