210 throw e;
211 } catch (Throwable t) {
212 assert e == t;
213 debug.handle(t);
214 }
215 } catch (Throwable t) {
216 // The exception object should propagate all the way out through
217 // a disabled sandbox scope
218 Assert.assertEquals(e, t);
219 }
220 String logged = baos.toString();
221 Assert.assertTrue(logged, logged.isEmpty());
222 }
223
224 /**
225 * Tests that using a {@link DebugContext} on a thread other than the one on which it was
226 * created causes an assertion failure.
227 */
228 @Test
229 public void testInvariantChecking() throws InterruptedException {
230 Assume.assumeTrue(Assertions.ENABLED);
231 EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
232 // Configure with an option that enables counters
233 map.put(DebugOptions.Counters, "");
234 OptionValues options = new OptionValues(map);
235 DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
236 CounterKey counter = DebugContext.counter("DebugContextTestCounter");
237 AssertionError[] result = {null};
238 Thread thread = new Thread() {
239
240 @Override
241 public void run() {
242 try {
243 counter.add(debug, 1);
244 } catch (AssertionError e) {
245 result[0] = e;
246 }
247 }
248 };
249 thread.start();
250 thread.join();
|
210 throw e;
211 } catch (Throwable t) {
212 assert e == t;
213 debug.handle(t);
214 }
215 } catch (Throwable t) {
216 // The exception object should propagate all the way out through
217 // a disabled sandbox scope
218 Assert.assertEquals(e, t);
219 }
220 String logged = baos.toString();
221 Assert.assertTrue(logged, logged.isEmpty());
222 }
223
224 /**
225 * Tests that using a {@link DebugContext} on a thread other than the one on which it was
226 * created causes an assertion failure.
227 */
228 @Test
229 public void testInvariantChecking() throws InterruptedException {
230 Assume.assumeTrue(Assertions.assertionsEnabled());
231 EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
232 // Configure with an option that enables counters
233 map.put(DebugOptions.Counters, "");
234 OptionValues options = new OptionValues(map);
235 DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
236 CounterKey counter = DebugContext.counter("DebugContextTestCounter");
237 AssertionError[] result = {null};
238 Thread thread = new Thread() {
239
240 @Override
241 public void run() {
242 try {
243 counter.add(debug, 1);
244 } catch (AssertionError e) {
245 result[0] = e;
246 }
247 }
248 };
249 thread.start();
250 thread.join();
|