32 /**
33 * Regression for 6426129 abort() after close() throws
34 * NoSuchElementException.
35 */
36 public class TestAbort {
37 static boolean aborted = false;
38
39 public static void
40 main(String[] args)
41 {
42 Consumer consumer = new LocalConsumer();
43
44 // Test for deadlock (bug 6419880)
45 try {
46 consumer.open();
47 consumer.compile("syscall:::entry { @[execname] = count(); } " +
48 "tick-101ms { printa(@); }");
49 consumer.enable();
50 consumer.go();
51 try {
52 Thread.currentThread().sleep(1000);
53 } catch (InterruptedException e) {
54 e.printStackTrace();
55 System.exit(1);
56 }
57 consumer.close();
58 } catch (DTraceException e) {
59 e.printStackTrace();
60 System.exit(1);
61 }
62
63 consumer = new LocalConsumer();
64
65 // Should be able to abort an unopened consumer
66 try {
67 aborted = false;
68 consumer.addConsumerListener(new ConsumerAdapter() {
69 public void consumerStopped(ConsumerEvent e) {
70 aborted = true;
71 }
72 });
73 consumer.abort();
74 consumer.open();
75 consumer.compile("syscall:::entry { @[execname] = count(); } " +
76 "tick-101ms { printa(@); }");
77 consumer.enable();
78 consumer.go();
79 try {
80 Thread.currentThread().sleep(1000);
81 } catch (InterruptedException e) {
82 e.printStackTrace();
83 System.exit(1);
84 }
85 if (!aborted) {
86 throw new IllegalStateException("consumer not aborted");
87 }
88 consumer.close();
89 } catch (Exception e) {
90 e.printStackTrace();
91 System.exit(1);
92 }
93
94 consumer = new LocalConsumer();
95
96 // Should be safe to call abort() in any state
97 try {
98 consumer.abort();
99 consumer.open();
100 consumer.abort();
112 } catch (NoSuchElementException e) {
113 e.printStackTrace();
114 System.exit(1);
115 }
116 } catch (Exception e) {
117 e.printStackTrace();
118 System.exit(1);
119 }
120
121 consumer = new LocalConsumer();
122
123 // Tests that close() throws expected exception when called on
124 // synchronized consumer.
125 try {
126 consumer.open();
127 consumer.compile("syscall:::entry { @[execname] = count(); } " +
128 "tick-101ms { printa(@); }");
129 consumer.enable();
130 consumer.go();
131 try {
132 Thread.currentThread().sleep(1000);
133 } catch (InterruptedException e) {
134 e.printStackTrace();
135 System.exit(1);
136 }
137 try {
138 synchronized (consumer) {
139 consumer.close();
140 }
141 } catch (IllegalThreadStateException e) {
142 try {
143 consumer.close();
144 System.out.println("Successful");
145 System.exit(0);
146 } catch (NoSuchElementException x) {
147 x.printStackTrace();
148 System.exit(1);
149 }
150 }
151 } catch (DTraceException e) {
152 e.printStackTrace();
|
32 /**
33 * Regression for 6426129 abort() after close() throws
34 * NoSuchElementException.
35 */
36 public class TestAbort {
37 static boolean aborted = false;
38
39 public static void
40 main(String[] args)
41 {
42 Consumer consumer = new LocalConsumer();
43
44 // Test for deadlock (bug 6419880)
45 try {
46 consumer.open();
47 consumer.compile("syscall:::entry { @[execname] = count(); } " +
48 "tick-101ms { printa(@); }");
49 consumer.enable();
50 consumer.go();
51 try {
52 Thread.sleep(1000);
53 } catch (InterruptedException e) {
54 e.printStackTrace();
55 System.exit(1);
56 }
57 consumer.close();
58 } catch (DTraceException e) {
59 e.printStackTrace();
60 System.exit(1);
61 }
62
63 consumer = new LocalConsumer();
64
65 // Should be able to abort an unopened consumer
66 try {
67 aborted = false;
68 consumer.addConsumerListener(new ConsumerAdapter() {
69 public void consumerStopped(ConsumerEvent e) {
70 aborted = true;
71 }
72 });
73 consumer.abort();
74 consumer.open();
75 consumer.compile("syscall:::entry { @[execname] = count(); } " +
76 "tick-101ms { printa(@); }");
77 consumer.enable();
78 consumer.go();
79 try {
80 Thread.sleep(1000);
81 } catch (InterruptedException e) {
82 e.printStackTrace();
83 System.exit(1);
84 }
85 if (!aborted) {
86 throw new IllegalStateException("consumer not aborted");
87 }
88 consumer.close();
89 } catch (Exception e) {
90 e.printStackTrace();
91 System.exit(1);
92 }
93
94 consumer = new LocalConsumer();
95
96 // Should be safe to call abort() in any state
97 try {
98 consumer.abort();
99 consumer.open();
100 consumer.abort();
112 } catch (NoSuchElementException e) {
113 e.printStackTrace();
114 System.exit(1);
115 }
116 } catch (Exception e) {
117 e.printStackTrace();
118 System.exit(1);
119 }
120
121 consumer = new LocalConsumer();
122
123 // Tests that close() throws expected exception when called on
124 // synchronized consumer.
125 try {
126 consumer.open();
127 consumer.compile("syscall:::entry { @[execname] = count(); } " +
128 "tick-101ms { printa(@); }");
129 consumer.enable();
130 consumer.go();
131 try {
132 Thread.sleep(1000);
133 } catch (InterruptedException e) {
134 e.printStackTrace();
135 System.exit(1);
136 }
137 try {
138 synchronized (consumer) {
139 consumer.close();
140 }
141 } catch (IllegalThreadStateException e) {
142 try {
143 consumer.close();
144 System.out.println("Successful");
145 System.exit(0);
146 } catch (NoSuchElementException x) {
147 x.printStackTrace();
148 System.exit(1);
149 }
150 }
151 } catch (DTraceException e) {
152 e.printStackTrace();
|