Mercurial > hg > Members > kono > jpf-core
comparison src/tests/gov/nasa/jpf/test/java/concurrent/ExchangerTest.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
1 /* | |
2 * Copyright (C) 2014, United States Government, as represented by the | |
3 * Administrator of the National Aeronautics and Space Administration. | |
4 * All rights reserved. | |
5 * | |
6 * The Java Pathfinder core (jpf-core) platform is licensed under the | |
7 * Apache License, Version 2.0 (the "License"); you may not use this file except | |
8 * in compliance with the License. You may obtain a copy of the License at | |
9 * | |
10 * http://www.apache.org/licenses/LICENSE-2.0. | |
11 * | |
12 * Unless required by applicable law or agreed to in writing, software | |
13 * distributed under the License is distributed on an "AS IS" BASIS, | |
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 * See the License for the specific language governing permissions and | |
16 * limitations under the License. | |
17 */ | |
18 package gov.nasa.jpf.test.java.concurrent; | |
19 | |
20 import gov.nasa.jpf.util.test.TestJPF; | |
21 import gov.nasa.jpf.vm.Verify; | |
22 import java.util.concurrent.Exchanger; | |
23 import java.util.concurrent.TimeUnit; | |
24 import org.junit.Test; | |
25 | |
26 /** | |
27 * regression test for java.util.concurrent.Exchanger | |
28 */ | |
29 public class ExchangerTest extends TestJPF { | |
30 | |
31 static Exchanger<String> exchanger = new Exchanger<String>(); | |
32 | |
33 static class ExTo extends Thread { | |
34 @Override | |
35 public void run() { | |
36 try { | |
37 //interrupt(); | |
38 System.out.println("T now exchanging.."); | |
39 | |
40 String response = exchanger.exchange("hi", 1000, TimeUnit.MILLISECONDS); | |
41 | |
42 System.out.print("T got: "); | |
43 System.out.println(response); | |
44 | |
45 assertTrue(response.equals("there")); | |
46 Verify.setBitInBitSet(0, 0, true); | |
47 | |
48 } catch (Throwable x) { | |
49 System.out.print("T got exception: "); | |
50 System.out.println(x); | |
51 Verify.setBitInBitSet(0, 1, true); | |
52 } | |
53 } | |
54 } | |
55 | |
56 @Test | |
57 public void testTimeoutExchange() { | |
58 | |
59 if (verifyNoPropertyViolation()){ | |
60 Thread t = new ExTo(); | |
61 t.start(); | |
62 | |
63 try { | |
64 System.out.println("M now exchanging.."); | |
65 | |
66 String response = exchanger.exchange("there", 100, TimeUnit.MILLISECONDS); | |
67 | |
68 System.out.print("M got: "); | |
69 System.out.println(response); | |
70 assertTrue(response.equals("hi")); | |
71 Verify.setBitInBitSet(0, 2, true); | |
72 | |
73 | |
74 } catch (Throwable x){ | |
75 System.out.print("M got exception: "); | |
76 System.out.println( x); | |
77 Verify.setBitInBitSet(0, 3, true); | |
78 } | |
79 | |
80 } else { // not executed under JPF | |
81 // check if we saw each path at least once | |
82 assertTrue( Verify.getBitInBitSet(0, 0)); | |
83 assertTrue( Verify.getBitInBitSet(0, 1)); | |
84 assertTrue( Verify.getBitInBitSet(0, 2)); | |
85 assertTrue( Verify.getBitInBitSet(0, 3)); | |
86 } | |
87 } | |
88 } |