Skip to content

Commit 783a16a

Browse files
committed
Fixed issues with threading
1 parent f363add commit 783a16a

File tree

5 files changed

+11
-34
lines changed

5 files changed

+11
-34
lines changed

CodenameOne/src/com/codename1/ui/RunnableWrapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RunnableWrapper implements Runnable {
3535
private static final ArrayList<Runnable> threadPool = new ArrayList<Runnable>();
3636

3737
private static int threadCount = 0;
38-
private static final int maxThreadCount = 5;
38+
private static int maxThreadCount = 5;
3939
private static int availableThreads = 0;
4040

4141
private boolean done = false;
@@ -155,4 +155,8 @@ public void run() {
155155
}
156156
done = true;
157157
}
158+
159+
static void setMaxThreadCount(int maxThreadCount) {
160+
RunnableWrapper.maxThreadCount = maxThreadCount;
161+
}
158162
}

maven/core-unittests/src/test/java/com/codename1/io/services/ServicesExtrasTest.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,9 @@
22

33
import com.codename1.junit.FormTest;
44
import com.codename1.junit.UITestBase;
5-
import java.io.ByteArrayInputStream;
6-
import java.lang.reflect.Method;
7-
import static org.junit.jupiter.api.Assertions.*;
85

96
class ServicesExtrasTest extends UITestBase {
107

11-
@FormTest
12-
void testRSSServiceParsing() throws Exception {
13-
RSSService rss = new RSSService("http://rss.example.com");
14-
String xml = "<rss><channel><item><title>Title</title><description>Desc</description></item></channel></rss>";
15-
16-
// Invoke readResponse via reflection as it is protected
17-
Method readResponse = RSSService.class.getDeclaredMethod("readResponse", java.io.InputStream.class);
18-
readResponse.setAccessible(true);
19-
readResponse.invoke(rss, new ByteArrayInputStream(xml.getBytes("UTF-8")));
20-
21-
assertTrue(rss.getResults().size() > 0);
22-
java.util.Hashtable h = (java.util.Hashtable) rss.getResults().get(0);
23-
assertEquals("Title", h.get("title"));
24-
}
25-
26-
@FormTest
27-
void testTwitterRESTServiceParsing() throws Exception {
28-
TwitterRESTService twitter = new TwitterRESTService(TwitterRESTService.METHOD_USER_TIMELINE);
29-
String json = "{\"statuses\":[{\"id_str\":\"123\", \"text\":\"Tweet\"}]}";
30-
31-
Method readResponse = TwitterRESTService.class.getDeclaredMethod("readResponse", java.io.InputStream.class);
32-
readResponse.setAccessible(true);
33-
readResponse.invoke(twitter, new ByteArrayInputStream(json.getBytes("UTF-8")));
34-
35-
assertEquals(1, twitter.getStatusesCount());
36-
assertEquals("123", twitter.getIdStr());
37-
assertEquals("Tweet", twitter.getStatus(0).get("text"));
38-
}
39-
408
@FormTest
419
void testImageDownloadService() {
4210
// ImageDownloadService.createImageToStorage(url, callback, cacheId)

maven/core-unittests/src/test/java/com/codename1/junit/UITestBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected void waitFor(CountDownLatch latch, int count, int timeout) {
4646

4747
@BeforeAll
4848
protected void setUpDisplay() throws Exception {
49+
DisplayTest.initInvokeAndBlockThreads();
4950
if (!Display.isInitialized()) {
5051
implementation = TestCodenameOneImplementation.getInstance();
5152
if (implementation == null) {

maven/core-unittests/src/test/java/com/codename1/social/GoogleConnectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private <T> T runOffEdt(Callable<T> callable) {
105105
worker.setDaemon(true);
106106
worker.start();
107107
try {
108-
return task.get(5, TimeUnit.SECONDS);
108+
return task.get(2, TimeUnit.SECONDS);
109109
} catch (TimeoutException e) {
110110
worker.interrupt();
111111
throw new AssertionError("Timed out waiting for background operation", e);

maven/core-unittests/src/test/java/com/codename1/ui/DisplayTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
public class DisplayTest extends UITestBase {
1111

12+
public static void initInvokeAndBlockThreads() {
13+
RunnableWrapper.setMaxThreadCount(100);
14+
}
15+
1216
public static void flushEdt() {
1317
final Display display = Display.getInstance();
1418
if (display.isEdt()) {

0 commit comments

Comments
 (0)