[Android] Use an executor to invoke the formatting routines from multiple threads concurrently
Robert Stone
git at videolan.org
Tue Dec 1 10:42:24 CET 2020
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Tue Dec 1 00:27:11 2020 -0800| [35919775d32816fee5124388b6d2bdcb24fd9032] | committer: Nicolas Pomepuy
Use an executor to invoke the formatting routines from multiple threads concurrently
> https://code.videolan.org/videolan/vlc-android/commit/35919775d32816fee5124388b6d2bdcb24fd9032
---
medialibrary/build.gradle | 4 ++
.../test/org/videolan/medialibrary/ToolsTest.java | 62 ++++++++++++++++------
2 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/medialibrary/build.gradle b/medialibrary/build.gradle
index 14620bf36..41af6a94e 100644
--- a/medialibrary/build.gradle
+++ b/medialibrary/build.gradle
@@ -33,6 +33,10 @@ ext {
libraryDescription = 'Android bindings and API for Medialibrary'
}
android {
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
diff --git a/medialibrary/test/org/videolan/medialibrary/ToolsTest.java b/medialibrary/test/org/videolan/medialibrary/ToolsTest.java
index dca3bdb7f..7e3a41400 100644
--- a/medialibrary/test/org/videolan/medialibrary/ToolsTest.java
+++ b/medialibrary/test/org/videolan/medialibrary/ToolsTest.java
@@ -1,29 +1,59 @@
package org.videolan.medialibrary;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
- at RunWith(JUnit4::class)
public class ToolsTest {
- @Test
- public void testIsArrayEmpty() {
+ @Test
+ public void testMillisToString() {
+ assertEquals("3min30s", Tools.millisToString(210000, true, true, false));
+ assertEquals("3min 30s ", Tools.millisToString(210000, true, true, true));
+ assertEquals("3min", Tools.millisToString(180000, true, true, false));
+ assertEquals("3min ", Tools.millisToString(180000, true, true, true));
+ assertEquals("1h30min30s", Tools.millisToString(5430000, true, true, false));
+ assertEquals("1h 30min 30s ", Tools.millisToString(5430000, true, true, true));
+ assertEquals("1h30min", Tools.millisToString(5430000, true, false, false));
+ assertEquals("1h 30min ", Tools.millisToString(5430000, true, false, true));
+ assertEquals("1h30min", Tools.millisToString(5400000, true, true, false));
+ assertEquals("17s", Tools.millisToString(17000, true, true, false));
+ assertEquals("17s ", Tools.millisToString(17000, true, true, true));
+ assertEquals("17s", Tools.millisToString(17000, true, false, false));
+ assertEquals("17s ", Tools.millisToString(17000, true, false, true));
+ assertEquals("1h30s", Tools.millisToString(3630000, true, true, false));
+ assertEquals("1h 30s ", Tools.millisToString(3630000, true, true, true));
+ assertEquals("-32:40", Tools.millisToString(-1960000, false, true, false));
}
+ /**
+ * Perform multi-threaded testing of the duration formatting routines.
+ */
@Test
- public void testMillisToString() {
- assertEquals("3min30s", Tools.millisToString(210000, true, true));
- assertEquals("3min", Tools.millisToString(180000, true, true));
- assertEquals("1h30min30s", Tools.millisToString(5430000, true, true));
- assertEquals("1h30min", Tools.millisToString(5430000, true, false));
- assertEquals("1h30min", Tools.millisToString(5400000, true, true));
- assertEquals("17s", Tools.millisToString(17000, true, true));
- assertEquals("17s", Tools.millisToString(17000, true, false));
- assertEquals("1h30s", Tools.millisToString(3630000, true, true));
- assertEquals("-32:40", Tools.millisToString(-1960000, false, true));
+ public void testConcurrentMillisToString() throws ExecutionException, InterruptedException {
+ List<Future> futureList = new ArrayList<>();
+ ExecutorService exec = Executors.newFixedThreadPool(2);
+ futureList.add(exec.submit(() -> {
+ for (int i = 0; i < 100; i++) {
+ assertEquals("3min30s", Tools.millisToString(210000, true, true, false));
+ assertEquals("-32:40", Tools.millisToString(-1960000, false, true, false));
+ }
+ }));
+ futureList.add(exec.submit(() -> {
+ for (int i = 0; i < 100; i++) {
+ assertEquals("3min", Tools.millisToString(180000, true, true, false));
+ assertEquals("54:32:10", Tools.millisToString(196330000L, false, true, false));
+ }
+ }));
+ for (Future f : futureList) f.get();
+ exec.shutdown();
+ exec.awaitTermination(10, TimeUnit.SECONDS);
}
}
\ No newline at end of file
More information about the Android
mailing list