Skip to content

Commit d709d60

Browse files
author
gitlab
committed
Merge branch 'ZSTAC-52782@@2' into 'master'
<fix>[compute]: strat ping right now See merge request zstackio/zstack!3495
2 parents 5e4f76d + c28cd0a commit d709d60

5 files changed

Lines changed: 30 additions & 22 deletions

File tree

compute/src/main/java/org/zstack/compute/host/HostTrackImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class HostTrackImpl implements HostTracker, ManagementNodeChangeListener,
3434
private final static CLogger logger = Utils.getLogger(HostTrackImpl.class);
3535

3636
private Map<String, Tracker> trackers = new HashMap<>();
37+
private static boolean alwaysStartRightNow = false;
3738

3839
@Autowired
3940
private DatabaseFacade dbf;
@@ -241,7 +242,7 @@ public void trackHost(String hostUuid) {
241242
t = new Tracker(hostUuid);
242243
trackers.put(hostUuid, t);
243244

244-
if (CoreGlobalProperty.UNIT_TEST_ON) {
245+
if (CoreGlobalProperty.UNIT_TEST_ON && !alwaysStartRightNow) {
245246
t.start();
246247
} else {
247248
t.startRightNow();

core/src/main/java/org/zstack/core/thread/AsyncTimer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void startRightNow() {
6363
throw new CloudRuntimeException("cannot start a cancelled timer");
6464
}
6565

66-
cancel = thdf.submitTimeoutTask(this, getTimeUnit(), getPeriod(), true);
66+
cancel = thdf.submitTimeoutTask(this, getTimeUnit(), 0);
6767
if (logger.isTraceEnabled()) {
6868
logger.trace(String.format("%s starts", getName()));
6969
}

core/src/main/java/org/zstack/core/thread/ThreadFacade.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public interface ThreadFacade extends Component {
4343

4444
ThreadFacadeImpl.TimeoutTaskReceipt submitTimeoutTask(Runnable task, TimeUnit unit, long delay);
4545

46-
ThreadFacadeImpl.TimeoutTaskReceipt submitTimeoutTask(Runnable task, TimeUnit unit, long delay, boolean executeRightNow);
47-
4846
Runnable submitTimerTask(TimerTask task, TimeUnit unit, long delay);
4947

5048
int getSyncThreadNum(int totalThreadNum);

core/src/main/java/org/zstack/core/thread/ThreadFacadeImpl.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,7 @@ public interface TimeoutTaskReceipt {
259259
}
260260

261261
@Override
262-
public TimeoutTaskReceipt submitTimeoutTask(final Runnable task, TimeUnit unit, long delay) {
263-
return submitTimeoutTask(task, unit, delay, false);
264-
}
265-
266-
@Override
267-
public TimeoutTaskReceipt submitTimeoutTask(Runnable task, TimeUnit unit, long delay, boolean executeRightNow) {
262+
public TimeoutTaskReceipt submitTimeoutTask(Runnable task, TimeUnit unit, long delay) {
268263
final TimerWrapper timer = timerPool.getTimer();
269264

270265
class TimerTaskWorker extends java.util.TimerTask implements TimeoutTaskReceipt {
@@ -290,21 +285,9 @@ public boolean cancel() {
290285

291286
TimerTaskWorker worker = new TimerTaskWorker();
292287
timer.schedule(worker, unit.toMillis(delay));
293-
if (executeRightNow) {
294-
executeRightNow(task);
295-
}
296288
return worker;
297289
}
298290

299-
@AsyncThread
300-
private void executeRightNow(final Runnable task) {
301-
try {
302-
task.run();
303-
} catch (Throwable t) {
304-
_logger.warn(String.format("Unhandled exception happened when running %s", task.getClass().getName()), t);
305-
}
306-
}
307-
308291
@Override
309292
public Runnable submitTimerTask(final TimerTask task, TimeUnit unit, long delay) {
310293
final TimerWrapper timer = timerPool.getTimer();

test/src/test/groovy/org/zstack/test/integration/core/AsyncTimerCase.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ class AsyncTimerCase extends SubCase {
4545
assert total == count
4646
}
4747

48+
void testStartRightNow() {
49+
int count = 0
50+
int total = 3
51+
52+
def timer = new AsyncTimer(TimeUnit.MILLISECONDS, 100L) {
53+
@Override
54+
protected void execute() {
55+
count ++
56+
if (count < total) {
57+
continueToRunThisTimer()
58+
}
59+
}
60+
}
61+
62+
timer.startRightNow()
63+
64+
TimeUnit.MILLISECONDS.sleep((total - 1) * 100)
65+
retryInSecs {
66+
assert total == count
67+
}
68+
69+
TimeUnit.MILLISECONDS.sleep(2L * 100)
70+
assert total == count
71+
}
72+
4873
void testCancel() {
4974
int count = 0
5075

@@ -68,6 +93,7 @@ class AsyncTimerCase extends SubCase {
6893
@Override
6994
void test() {
7095
testRun()
96+
testStartRightNow()
7197
testCancel()
7298
}
7399
}

0 commit comments

Comments
 (0)