author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Sun, 09 Nov 2014 10:36:08 +0100 | |
changeset 1722 | fd3a354d6e8f |
permissions | -rw-r--r-- |
jaroslav@1407 | 1 |
/** |
jaroslav@1407 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@1407 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@1407 | 4 |
* |
jaroslav@1407 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@1407 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@1407 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@1407 | 8 |
* |
jaroslav@1407 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@1407 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@1407 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@1407 | 12 |
* GNU General Public License for more details. |
jaroslav@1407 | 13 |
* |
jaroslav@1407 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@1407 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@1407 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@1407 | 17 |
*/ |
jaroslav@1407 | 18 |
package org.apidesign.bck2brwsr.tck; |
jaroslav@1407 | 19 |
|
jaroslav@1407 | 20 |
import java.util.Timer; |
jaroslav@1407 | 21 |
import java.util.TimerTask; |
jaroslav@1407 | 22 |
import org.apidesign.bck2brwsr.vmtest.BrwsrTest; |
jaroslav@1407 | 23 |
import org.apidesign.bck2brwsr.vmtest.VMTest; |
jaroslav@1407 | 24 |
import org.testng.annotations.Factory; |
jaroslav@1407 | 25 |
|
jaroslav@1407 | 26 |
/** |
jaroslav@1407 | 27 |
* |
jaroslav@1407 | 28 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@1407 | 29 |
*/ |
jaroslav@1407 | 30 |
public class TimerTest { |
jaroslav@1407 | 31 |
int miss; |
jaroslav@1407 | 32 |
int exec; |
jaroslav@1407 | 33 |
|
jaroslav@1407 | 34 |
public TimerTest() { |
jaroslav@1407 | 35 |
} |
jaroslav@1407 | 36 |
|
jaroslav@1407 | 37 |
@BrwsrTest public void scheduleTick() throws Exception { |
jaroslav@1407 | 38 |
Timer t = new Timer("MyTest"); |
jaroslav@1407 | 39 |
class TT extends TimerTask { |
jaroslav@1407 | 40 |
@Override |
jaroslav@1407 | 41 |
public void run() { |
jaroslav@1407 | 42 |
exec++; |
jaroslav@1407 | 43 |
} |
jaroslav@1407 | 44 |
} |
jaroslav@1407 | 45 |
TT task = new TT(); |
jaroslav@1407 | 46 |
t.schedule(task, 15); |
jaroslav@1407 | 47 |
|
jaroslav@1407 | 48 |
if (exec == 0) { |
jaroslav@1407 | 49 |
miss++; |
jaroslav@1407 | 50 |
throw new InterruptedException(); |
jaroslav@1407 | 51 |
} |
jaroslav@1407 | 52 |
|
jaroslav@1407 | 53 |
assert exec == 1 : "One exec: " + exec; |
jaroslav@1407 | 54 |
assert miss == 1 : "One miss: " + miss; |
jaroslav@1407 | 55 |
} |
jaroslav@1407 | 56 |
|
jaroslav@1407 | 57 |
@BrwsrTest public void repeatedTicks() throws Exception { |
jaroslav@1407 | 58 |
Timer t = new Timer("MyTest"); |
jaroslav@1407 | 59 |
class TT extends TimerTask { |
jaroslav@1407 | 60 |
@Override |
jaroslav@1407 | 61 |
public void run() { |
jaroslav@1407 | 62 |
exec++; |
jaroslav@1407 | 63 |
} |
jaroslav@1407 | 64 |
} |
jaroslav@1407 | 65 |
TT task = new TT(); |
jaroslav@1407 | 66 |
t.scheduleAtFixedRate(task, 15, 10); |
jaroslav@1407 | 67 |
|
jaroslav@1407 | 68 |
if (exec != 2) { |
jaroslav@1407 | 69 |
miss++; |
jaroslav@1407 | 70 |
throw new InterruptedException(); |
jaroslav@1407 | 71 |
} |
jaroslav@1407 | 72 |
|
jaroslav@1407 | 73 |
assert exec == 2 : "Two execs: " + exec; |
jaroslav@1407 | 74 |
assert miss == 2 : "Two misses: " + miss; |
jaroslav@1407 | 75 |
} |
jaroslav@1407 | 76 |
|
jaroslav@1407 | 77 |
@Factory public static Object[] create() { |
jaroslav@1407 | 78 |
return VMTest.create(TimerTest.class); |
jaroslav@1407 | 79 |
} |
jaroslav@1407 | 80 |
|
jaroslav@1407 | 81 |
} |