-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZK-5611: Executions.schedule() might fail if it's called by multiple …
…threads
- Loading branch information
1 parent
084806a
commit e9f798a
Showing
7 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
B96-ZK-5611.zul | ||
Purpose: | ||
Description: | ||
History: | ||
Thu Jan 25 17:10:14 CST 2024, Created by jamson | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
--> | ||
<zk> | ||
<label multiline="true"> | ||
1. Click start button, and you should see a new row with 3 threads' name below the button (e.g. 0 2 1). | ||
2. Keep clicking the button, the order of threads might be different, but the number of the threads should ALWAYS be 3. | ||
3. The name of 3 threads should be all-different. | ||
</label> | ||
<div apply="org.zkoss.zktest.test2.B96_ZK_5611_Composer"> | ||
<button label="schedule"/> | ||
</div> | ||
</zk> |
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
54 changes: 54 additions & 0 deletions
54
zktest/src/org/zkoss/zktest/test2/B96_ZK_5611_Composer.java
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* B96_ZK_5611_Composer.java | ||
Purpose: | ||
Description: | ||
History: | ||
Thu Jan 25 17:11:30 CST 2024, Created by jamson | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.test2; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.zkoss.zk.ui.Component; | ||
import org.zkoss.zk.ui.Desktop; | ||
import org.zkoss.zk.ui.Executions; | ||
import org.zkoss.zk.ui.event.Event; | ||
import org.zkoss.zk.ui.select.SelectorComposer; | ||
import org.zkoss.zk.ui.select.annotation.Listen; | ||
import org.zkoss.zul.Hlayout; | ||
import org.zkoss.zul.Label; | ||
|
||
public class B96_ZK_5611_Composer extends SelectorComposer { | ||
|
||
private int hlayoutId; | ||
private Component comp; | ||
private Desktop desktop; | ||
|
||
@Override | ||
public void doAfterCompose(Component comp) throws Exception { | ||
super.doAfterCompose(comp); | ||
this.comp = comp; | ||
Executions.getCurrent().getDesktop().enableServerPush(true); | ||
hlayoutId = 0; | ||
desktop = comp.getDesktop(); | ||
} | ||
|
||
@Listen("onClick = button") | ||
public void start(){ | ||
Hlayout hlayout = new Hlayout(); | ||
hlayout.setId("hlayout" + hlayoutId++); | ||
comp.appendChild(hlayout); | ||
for (int i = 0 ; i < 3 ; i++) { | ||
String taskId = String.valueOf(i); | ||
CompletableFuture.runAsync(() -> { | ||
Executions.schedule(desktop, event -> { | ||
hlayout.appendChild(new Label(taskId)); | ||
}, new Event("myEvent")); | ||
}); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
zktest/test/java/org/zkoss/zktest/zats/test2/B96_ZK_5611Test.java
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* B96_ZK_5611Test.java | ||
Purpose: | ||
Description: | ||
History: | ||
Thu Jan 25 18:07:48 CST 2024, Created by jamson | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.zats.test2; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.HashSet; | ||
|
||
import org.junit.Test; | ||
|
||
import org.zkoss.zktest.zats.WebDriverTestCase; | ||
import org.zkoss.zktest.zats.ztl.JQuery; | ||
|
||
public class B96_ZK_5611Test extends WebDriverTestCase { | ||
|
||
@Test | ||
public void test() { | ||
connect(); | ||
for (int i = 0; i < 100; ++i) | ||
click(jq("@button")); | ||
try { | ||
Thread.sleep(2000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
for (int i = 0; i < 100; ++i) { | ||
System.out.println("[Test 5611 LOG] times " + i); | ||
JQuery children = jq("$hlayout" + i).eq(0).children(); | ||
// check whether the number of children is 3 (all threads exists) | ||
assertEquals(3, children.length()); | ||
System.out.println("[Test 5611 LOG] threads : 3"); | ||
|
||
// check the 3 threads ID are 0, 1, 2 (no duplicate) | ||
HashSet<String> ids = new HashSet<String>(); | ||
for (int j = 0; j < 3; ++j) | ||
ids.add(children.get(j).firstChild().get("innerHTML")); | ||
assertEquals(3, ids.size()); | ||
System.out.println("[Test 5611 LOG] name all-different"); | ||
} | ||
} | ||
} |