[ThreadOpt]线程池插件版本升级,修正RxJava定时器问题
This commit is contained in:
@@ -10,7 +10,6 @@ if (!isAndroidTestBuild()) {
|
||||
}
|
||||
|
||||
//apply ByteX宿主
|
||||
|
||||
if (!isAndroidTestBuild()) {
|
||||
apply plugin: 'bytex'
|
||||
ByteX {
|
||||
@@ -21,15 +20,15 @@ if (!isAndroidTestBuild()) {
|
||||
}
|
||||
|
||||
if (!isAndroidTestBuild()) {
|
||||
// apply plugin: 'bytex.threadOpt'
|
||||
// thread_opt {
|
||||
// enable true
|
||||
// enableInDebug true
|
||||
// rxJavaIoReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getIoPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
// rxJavaComputationReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getCpuPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
// coroutineIoReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getIoPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
// coroutineDefaultReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getCpuPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
// }
|
||||
apply plugin: 'bytex.threadOpt'
|
||||
thread_opt {
|
||||
enable true
|
||||
enableInDebug true
|
||||
rxJavaIoReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getIoPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
rxJavaComputationReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getCpuPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
coroutineIoReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getIoPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
coroutineDefaultReplacer 'com/mogo/eagle/core/utilcode/util/ThreadUtils@@getCpuPool@@()Ljava/util/concurrent/ExecutorService;'
|
||||
}
|
||||
|
||||
/**
|
||||
* 方便使用systrace工具,在工程侧打点,便于分析工程侧性能问题
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.mogo.functions.test
|
||||
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
import com.mogo.eagle.core.function.main.MainLauncherActivity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class KotlinCoroutineSchedulersTest {
|
||||
|
||||
lateinit var launch: ActivityScenario<MainLauncherActivity>
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinCoroutineSchedulersIo() = runBlocking {
|
||||
launch.onActivity {
|
||||
it.lifecycle.coroutineScope.launchWhenCreated {
|
||||
repeat(10) {
|
||||
withContext(Dispatchers.IO) {
|
||||
assert(Thread.currentThread().name.startsWith("io-pool-"))
|
||||
}
|
||||
delay(TimeUnit.SECONDS.toMillis(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(TimeUnit.SECONDS.toMillis(20))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinCoroutineSchedulersCpu() = runBlocking {
|
||||
launch.onActivity {
|
||||
it.lifecycle.coroutineScope.launchWhenCreated {
|
||||
repeat(10) {
|
||||
withContext(Dispatchers.Default) {
|
||||
assert(Thread.currentThread().name.startsWith("cpu-pool-"))
|
||||
}
|
||||
delay(TimeUnit.SECONDS.toMillis(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(TimeUnit.SECONDS.toMillis(20))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mogo.functions.test
|
||||
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.LargeTest
|
||||
import com.mogo.eagle.core.function.main.MainLauncherActivity
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.ObservableOnSubscribe
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@LargeTest
|
||||
class RxJavaSchedulersTest {
|
||||
|
||||
lateinit var launch: ActivityScenario<MainLauncherActivity>
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
launch = ActivityScenario.launch(MainLauncherActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRxJavaIoSchedulers() = runBlocking {
|
||||
val list = mutableListOf<Int>()
|
||||
for (i in 1..10) {
|
||||
list += i
|
||||
}
|
||||
val result = Observable.fromIterable(list)
|
||||
.doOnNext {
|
||||
assert(Thread.currentThread().name.startsWith("io-pool-"))
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.reduce(0) { adder, toAdd ->
|
||||
val sum = adder + toAdd
|
||||
sum
|
||||
}
|
||||
.blockingGet()
|
||||
assert(result == 55)
|
||||
|
||||
delay(SECONDS.toMillis(20))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRxJavaCpuSchedulers() = runBlocking {
|
||||
val result = Observable.create(ObservableOnSubscribe<Int> { emitter ->
|
||||
for (i in 1..10) {
|
||||
emitter.onNext(i)
|
||||
}
|
||||
assert(Thread.currentThread().name.startsWith("cpu-pool-"))
|
||||
emitter.onComplete()
|
||||
}).reduce(0) { adder, toAdd ->
|
||||
adder + toAdd
|
||||
}.subscribeOn(Schedulers.computation()).blockingGet()
|
||||
assert(result == 55)
|
||||
delay(SECONDS.toMillis(20))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRxJavaIntervalSchedulers() = runBlocking {
|
||||
var counter = 0
|
||||
Observable.intervalRange(0, 10, 1, 1 ,SECONDS)
|
||||
.doOnNext {
|
||||
counter ++
|
||||
}
|
||||
.subscribe()
|
||||
delay(SECONDS.toMillis(20))
|
||||
assert(counter == 10)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +33,7 @@ buildscript {
|
||||
classpath "com.bytedance.android.byteX:base-plugin:0.3.0"
|
||||
classpath "com.mogo.cloud:hook:${HOOK_LOG_VERSION}"
|
||||
classpath 'com.volcengine:apm_insight_plugin:1.4.1'
|
||||
classpath 'com.mogo.cloud:thread_opt:1.0.0'
|
||||
classpath 'com.mogo.cloud:thread_opt:1.0.1'
|
||||
classpath 'com.mogo.cloud:systrace:1.0.1'
|
||||
|
||||
// classpath "com.bytedance.android.byteX:base-plugin:0.3.0"
|
||||
|
||||
Reference in New Issue
Block a user