001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest;
006:
007: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
008:
009: import com.tc.exception.TCLockUpgradeNotSupportedError;
010: import com.tc.object.config.ConfigLockLevel;
011: import com.tc.object.config.ConfigVisitor;
012: import com.tc.object.config.DSOClientConfigHelper;
013: import com.tc.object.config.LockDefinition;
014: import com.tc.object.config.LockDefinitionImpl;
015: import com.tc.object.config.spec.CyclicBarrierSpec;
016: import com.tc.simulator.app.ApplicationConfig;
017: import com.tc.simulator.listener.ListenerProvider;
018: import com.tc.util.Assert;
019: import com.tctest.runner.AbstractErrorCatchingTransparentApp;
020:
021: public class NamedLockUpgradeFailureTestApp extends
022: AbstractErrorCatchingTransparentApp {
023: private CyclicBarrier barrier;
024: private NameLockUpgradeClass root = new NameLockUpgradeClass();
025:
026: public NamedLockUpgradeFailureTestApp(String appId,
027: ApplicationConfig cfg, ListenerProvider listenerProvider) {
028: super (appId, cfg, listenerProvider);
029: this .barrier = new CyclicBarrier(getParticipantCount());
030: }
031:
032: public void runTest() throws Throwable {
033: int index = barrier.barrier();
034:
035: testMethodReturnObject(index);
036:
037: testMethodReturnInt(index);
038:
039: testMethodReturnLargeValue(index);
040:
041: testMethodVoid(index);
042: }
043:
044: private void testMethodReturnObject(int index) throws Throwable {
045: testNameLockWithinSingleNodeReturnObject(index);
046: }
047:
048: private void testMethodReturnInt(int index) throws Throwable {
049: testNameLockWithinSingleNodeReturnInt(index);
050: }
051:
052: private void testMethodReturnLargeValue(int index) throws Throwable {
053: testNameLockWithinSingleNodeReturnLong(index);
054:
055: testNameLockWithinSingleNodeReturnDouble(index);
056: }
057:
058: private void testMethodVoid(int index) throws Throwable {
059: testNameLockWithMultiNodes(index);
060:
061: testNameLockWithinSingleNode(index);
062: }
063:
064: private void testNameLockWithMultiNodes(int index) throws Throwable {
065: testNameLockUpgradeWithMultiNodes(index);
066: testNameLockThrowExceptionWithMultiNodes(index);
067: testNameLockUpgradeOnDifferentLocks1WithMultiNodes(index);
068: testNameLockUpgradeOnDifferentLocks2WithMultiNodes(index);
069: }
070:
071: private void testNameLockWithinSingleNode(int index)
072: throws Throwable {
073: testNameLockThrowException(index);
074:
075: testNameLockUpgrade(index);
076:
077: testNameLockUpgradeOnDifferentLocks1(index);
078:
079: testNameLockUpgradeOnDifferentLocks2(index);
080: }
081:
082: private void testNameLockWithinSingleNodeReturnObject(int index)
083: throws Throwable {
084: testNameLockUpgradeReturnObject(index);
085:
086: testNameLockThrowExceptionReturnObject(index);
087:
088: testNameLockUpgradeOnDifferentLocks1ReturnObject(index);
089:
090: testNameLockUpgradeOnDifferentLocks2ReturnObject(index);
091: }
092:
093: private void testNameLockWithinSingleNodeReturnInt(int index)
094: throws Throwable {
095: testNameLockUpgradeReturnInt(index);
096:
097: testNameLockThrowExceptionReturnInt(index);
098:
099: testNameLockUpgradeOnDifferentLocks1ReturnInt(index);
100:
101: testNameLockUpgradeOnDifferentLocks2ReturnInt(index);
102: }
103:
104: private void testNameLockWithinSingleNodeReturnLong(int index)
105: throws Throwable {
106: testNameLockUpgradeReturnLong(index);
107: }
108:
109: private void testNameLockWithinSingleNodeReturnDouble(int index)
110: throws Throwable {
111: testNameLockUpgradeReturnDouble(index);
112: }
113:
114: private void testNameLockUpgradeReturnDouble(int index)
115: throws Throwable {
116: if (index == 0) {
117: final CyclicBarrier localBarrier = new CyclicBarrier(2);
118: Thread t = new Thread(new Runnable() {
119: public void run() {
120: try {
121: localBarrier.barrier();
122: Assert.assertEquals(Double.MAX_VALUE, root
123: .doubleWrite());
124: } catch (Exception e) {
125: throw new AssertionError(e);
126: }
127: }
128: });
129:
130: t.start();
131: try {
132: root.doubleReadWrite(localBarrier);
133: throw new AssertionError(
134: "Should have thrown a TCLockUpgradeNotSupportedError.");
135: } catch (TCLockUpgradeNotSupportedError e) {
136: localBarrier.barrier();
137: }
138: }
139:
140: barrier.barrier();
141: }
142:
143: private void testNameLockUpgradeReturnLong(int index)
144: throws Throwable {
145: if (index == 0) {
146: final CyclicBarrier localBarrier = new CyclicBarrier(2);
147: Thread t = new Thread(new Runnable() {
148: public void run() {
149: try {
150: localBarrier.barrier();
151: Assert.assertEquals(Long.MAX_VALUE, root
152: .longWrite());
153: } catch (Exception e) {
154: throw new AssertionError(e);
155: }
156: }
157: });
158:
159: t.start();
160: try {
161: root.longReadWrite(localBarrier);
162: throw new AssertionError(
163: "Should have thrown a TCLockUpgradeNotSupportedError.");
164: } catch (TCLockUpgradeNotSupportedError e) {
165: localBarrier.barrier();
166: }
167: }
168:
169: barrier.barrier();
170: }
171:
172: private void testNameLockUpgradeReturnInt(int index)
173: throws Throwable {
174: if (index == 0) {
175: final CyclicBarrier localBarrier = new CyclicBarrier(2);
176: Thread t = new Thread(new Runnable() {
177: public void run() {
178: try {
179: localBarrier.barrier();
180: Assert.assertEquals(2, root.intWrite());
181: } catch (Exception e) {
182: throw new AssertionError(e);
183: }
184: }
185: });
186:
187: t.start();
188: try {
189: root.intReadWrite(localBarrier);
190: throw new AssertionError(
191: "Should have thrown a TCLockUpgradeNotSupportedError.");
192: } catch (TCLockUpgradeNotSupportedError e) {
193: localBarrier.barrier();
194: }
195: }
196:
197: barrier.barrier();
198: }
199:
200: private void testNameLockUpgradeReturnObject(int index)
201: throws Throwable {
202: if (index == 0) {
203: final CyclicBarrier localBarrier = new CyclicBarrier(2);
204: Thread t = new Thread(new Runnable() {
205: public void run() {
206: try {
207: localBarrier.barrier();
208: root.objWrite();
209: } catch (Exception e) {
210: throw new AssertionError(e);
211: }
212: }
213: });
214:
215: t.start();
216: try {
217: root.objReadWrite(localBarrier);
218: throw new AssertionError(
219: "Should have thrown a TCLockUpgradeNotSupportedError.");
220: } catch (TCLockUpgradeNotSupportedError e) {
221: localBarrier.barrier();
222: }
223: }
224:
225: barrier.barrier();
226: }
227:
228: private void testNameLockThrowExceptionWithMultiNodes(int index)
229: throws Throwable {
230: if (index == 0) {
231: barrier.barrier();
232: root.doWrite();
233: barrier.barrier();
234: } else if (index == 1) {
235: try {
236: root.doThrowException(barrier);
237: } catch (RuntimeException e) {
238: barrier.barrier();
239: }
240: }
241:
242: barrier.barrier();
243:
244: }
245:
246: private void testNameLockThrowException(int index) throws Throwable {
247: if (index == 0) {
248: final CyclicBarrier localBarrier = new CyclicBarrier(2);
249:
250: Thread t = new Thread(new Runnable() {
251: public void run() {
252: try {
253: localBarrier.barrier();
254: root.doWrite();
255: localBarrier.barrier();
256: } catch (Exception e) {
257: throw new AssertionError(e);
258: }
259: }
260: });
261:
262: t.start();
263: try {
264: root.doThrowException(localBarrier);
265: } catch (RuntimeException e) {
266: localBarrier.barrier();
267: }
268: }
269:
270: barrier.barrier();
271:
272: }
273:
274: private void testNameLockThrowExceptionReturnInt(int index)
275: throws Throwable {
276: if (index == 0) {
277: final CyclicBarrier localBarrier = new CyclicBarrier(2);
278:
279: Thread t = new Thread(new Runnable() {
280: public void run() {
281: try {
282: localBarrier.barrier();
283: Assert.assertEquals(2, root.intWrite());
284: localBarrier.barrier();
285: } catch (Exception e) {
286: throw new AssertionError(e);
287: }
288: }
289: });
290:
291: t.start();
292: try {
293: root.intThrowException(localBarrier);
294: } catch (RuntimeException e) {
295: localBarrier.barrier();
296: }
297: }
298:
299: barrier.barrier();
300:
301: }
302:
303: private void testNameLockThrowExceptionReturnObject(int index)
304: throws Throwable {
305: if (index == 0) {
306: final CyclicBarrier localBarrier = new CyclicBarrier(2);
307:
308: Thread t = new Thread(new Runnable() {
309: public void run() {
310: try {
311: localBarrier.barrier();
312: root.objWrite();
313: localBarrier.barrier();
314: } catch (Exception e) {
315: throw new AssertionError(e);
316: }
317: }
318: });
319:
320: t.start();
321: try {
322: root.objThrowException(localBarrier);
323: } catch (RuntimeException e) {
324: localBarrier.barrier();
325: }
326: }
327:
328: barrier.barrier();
329:
330: }
331:
332: private void testNameLockUpgrade(int index) throws Throwable {
333: if (index == 0) {
334: final CyclicBarrier localBarrier = new CyclicBarrier(2);
335: Thread t = new Thread(new Runnable() {
336: public void run() {
337: try {
338: localBarrier.barrier();
339: root.doWrite();
340: } catch (Exception e) {
341: throw new AssertionError(e);
342: }
343: }
344: });
345:
346: t.start();
347: try {
348: root.doReadWrite(localBarrier);
349: throw new AssertionError(
350: "Should have thrown a TCLockUpgradeNotSupportedError.");
351: } catch (TCLockUpgradeNotSupportedError e) {
352: localBarrier.barrier();
353: }
354: }
355:
356: barrier.barrier();
357: }
358:
359: private void testNameLockUpgradeWithMultiNodes(int index)
360: throws Throwable {
361: if (index == 0) {
362: barrier.barrier();
363: root.doWrite();
364: } else if (index == 1) {
365: try {
366: root.doReadWrite(barrier);
367: throw new AssertionError(
368: "Should have thrown a TCLockUpgradeNotSupportedError.");
369: } catch (TCLockUpgradeNotSupportedError e) {
370: barrier.barrier();
371: }
372: }
373:
374: barrier.barrier();
375: }
376:
377: private void testNameLockUpgradeOnDifferentLocks1WithMultiNodes(
378: int index) throws Throwable {
379: if (index == 0) {
380: barrier.barrier();
381: root.doWrite();
382: barrier.barrier();
383: } else if (index == 1) {
384: root.doReadWriteOnTwoNameLock(barrier);
385: barrier.barrier();
386: }
387:
388: barrier.barrier();
389: }
390:
391: private void testNameLockUpgradeOnDifferentLocks1(int index)
392: throws Throwable {
393: if (index == 0) {
394: final CyclicBarrier localBarrier = new CyclicBarrier(2);
395: Thread t = new Thread(new Runnable() {
396: public void run() {
397: try {
398: localBarrier.barrier();
399: root.doWrite();
400: localBarrier.barrier();
401: } catch (Exception e) {
402: throw new AssertionError(e);
403: }
404: }
405: });
406:
407: t.start();
408: root.doReadWriteOnTwoNameLock(localBarrier);
409: localBarrier.barrier();
410: }
411:
412: barrier.barrier();
413: }
414:
415: private void testNameLockUpgradeOnDifferentLocks1ReturnInt(int index)
416: throws Throwable {
417: if (index == 0) {
418: final CyclicBarrier localBarrier = new CyclicBarrier(2);
419: Thread t = new Thread(new Runnable() {
420: public void run() {
421: try {
422: localBarrier.barrier();
423: Assert.assertEquals(2, root.intWrite());
424: localBarrier.barrier();
425: } catch (Exception e) {
426: throw new AssertionError(e);
427: }
428: }
429: });
430:
431: t.start();
432: Assert.assertEquals(3, root
433: .intReadWriteOnTwoNameLock(localBarrier));
434: localBarrier.barrier();
435: }
436:
437: barrier.barrier();
438: }
439:
440: private void testNameLockUpgradeOnDifferentLocks1ReturnObject(
441: int index) throws Throwable {
442: if (index == 0) {
443: final CyclicBarrier localBarrier = new CyclicBarrier(2);
444: Thread t = new Thread(new Runnable() {
445: public void run() {
446: try {
447: localBarrier.barrier();
448: root.objWrite();
449: localBarrier.barrier();
450: } catch (Exception e) {
451: throw new AssertionError(e);
452: }
453: }
454: });
455:
456: t.start();
457: root.objReadWriteOnTwoNameLock(localBarrier);
458: localBarrier.barrier();
459: }
460:
461: barrier.barrier();
462: }
463:
464: private void testNameLockUpgradeOnDifferentLocks2WithMultiNodes(
465: int index) throws Throwable {
466: if (index == 0) {
467: barrier.barrier();
468: root.doWriteWithNameLock1();
469: barrier.barrier();
470: } else if (index == 1) {
471: root.doReadWriteOnTwoNameLock(barrier);
472: barrier.barrier();
473: }
474:
475: barrier.barrier();
476: }
477:
478: private void testNameLockUpgradeOnDifferentLocks2(int index)
479: throws Throwable {
480: if (index == 0) {
481: final CyclicBarrier localBarrier = new CyclicBarrier(2);
482: Thread t = new Thread(new Runnable() {
483: public void run() {
484: try {
485: localBarrier.barrier();
486: root.doWriteWithNameLock1();
487: localBarrier.barrier();
488: } catch (Exception e) {
489: throw new AssertionError(e);
490: }
491: }
492: });
493:
494: t.start();
495: root.doReadWriteOnTwoNameLock(localBarrier);
496: localBarrier.barrier();
497: }
498:
499: barrier.barrier();
500: }
501:
502: private void testNameLockUpgradeOnDifferentLocks2ReturnInt(int index)
503: throws Throwable {
504: if (index == 0) {
505: final CyclicBarrier localBarrier = new CyclicBarrier(2);
506: Thread t = new Thread(new Runnable() {
507: public void run() {
508: try {
509: localBarrier.barrier();
510: Assert.assertEquals(4, root
511: .intWriteWithNameLock1());
512: localBarrier.barrier();
513: } catch (Exception e) {
514: throw new AssertionError(e);
515: }
516: }
517: });
518:
519: t.start();
520: Assert.assertEquals(3, root
521: .intReadWriteOnTwoNameLock(localBarrier));
522: localBarrier.barrier();
523: }
524:
525: barrier.barrier();
526: }
527:
528: private void testNameLockUpgradeOnDifferentLocks2ReturnObject(
529: int index) throws Throwable {
530: if (index == 0) {
531: final CyclicBarrier localBarrier = new CyclicBarrier(2);
532: Thread t = new Thread(new Runnable() {
533: public void run() {
534: try {
535: localBarrier.barrier();
536: root.objWriteWithNameLock1();
537: localBarrier.barrier();
538: } catch (Exception e) {
539: throw new AssertionError(e);
540: }
541: }
542: });
543:
544: t.start();
545: root.objReadWriteOnTwoNameLock(localBarrier);
546: localBarrier.barrier();
547: }
548:
549: barrier.barrier();
550: }
551:
552: public static void visitL1DSOConfig(ConfigVisitor visitor,
553: DSOClientConfigHelper config) {
554: String testClass = NamedLockUpgradeFailureTestApp.class
555: .getName();
556:
557: config.getOrCreateSpec(testClass) //
558: .addRoot("barrier", "barrier") //
559: .addRoot("root", "root");
560:
561: config.getOrCreateSpec(NameLockUpgradeClass.class.getName());
562:
563: String methodExpression = "* " + testClass
564: + "$NameLockUpgradeClass.doReadWrite(..)";
565: LockDefinition definition = new LockDefinitionImpl("nameLock",
566: ConfigLockLevel.WRITE);
567: definition.commit();
568: config.addLock(methodExpression, definition);
569: definition = new LockDefinitionImpl("nameLock",
570: ConfigLockLevel.READ);
571: definition.commit();
572: config.addLock(methodExpression, definition);
573:
574: methodExpression = "* " + testClass
575: + "$NameLockUpgradeClass.intReadWrite(..)";
576: definition = new LockDefinitionImpl("nameLock",
577: ConfigLockLevel.WRITE);
578: definition.commit();
579: config.addLock(methodExpression, definition);
580: definition = new LockDefinitionImpl("nameLock",
581: ConfigLockLevel.READ);
582: definition.commit();
583: config.addLock(methodExpression, definition);
584:
585: methodExpression = "* " + testClass
586: + "$NameLockUpgradeClass.objReadWrite(..)";
587: definition = new LockDefinitionImpl("nameLock",
588: ConfigLockLevel.WRITE);
589: definition.commit();
590: config.addLock(methodExpression, definition);
591: definition = new LockDefinitionImpl("nameLock",
592: ConfigLockLevel.READ);
593: definition.commit();
594: config.addLock(methodExpression, definition);
595:
596: methodExpression = "* " + testClass
597: + "$NameLockUpgradeClass.longReadWrite(..)";
598: definition = new LockDefinitionImpl("nameLock",
599: ConfigLockLevel.WRITE);
600: definition.commit();
601: config.addLock(methodExpression, definition);
602: definition = new LockDefinitionImpl("nameLock",
603: ConfigLockLevel.READ);
604: definition.commit();
605: config.addLock(methodExpression, definition);
606:
607: methodExpression = "* " + testClass
608: + "$NameLockUpgradeClass.doubleReadWrite(..)";
609: definition = new LockDefinitionImpl("nameLock",
610: ConfigLockLevel.WRITE);
611: definition.commit();
612: config.addLock(methodExpression, definition);
613: definition = new LockDefinitionImpl("nameLock",
614: ConfigLockLevel.READ);
615: definition.commit();
616: config.addLock(methodExpression, definition);
617:
618: methodExpression = "* " + testClass
619: + "$NameLockUpgradeClass.doThrowException(..)";
620: definition = new LockDefinitionImpl("nameLock",
621: ConfigLockLevel.WRITE);
622: definition.commit();
623: config.addLock(methodExpression, definition);
624: definition = new LockDefinitionImpl("nameLock",
625: ConfigLockLevel.WRITE);
626: definition.commit();
627: config.addLock(methodExpression, definition);
628:
629: methodExpression = "* " + testClass
630: + "$NameLockUpgradeClass.intThrowException(..)";
631: definition = new LockDefinitionImpl("nameLock",
632: ConfigLockLevel.WRITE);
633: definition.commit();
634: config.addLock(methodExpression, definition);
635: definition = new LockDefinitionImpl("nameLock",
636: ConfigLockLevel.WRITE);
637: definition.commit();
638: config.addLock(methodExpression, definition);
639:
640: methodExpression = "* " + testClass
641: + "$NameLockUpgradeClass.objThrowException(..)";
642: definition = new LockDefinitionImpl("nameLock",
643: ConfigLockLevel.WRITE);
644: definition.commit();
645: config.addLock(methodExpression, definition);
646: definition = new LockDefinitionImpl("nameLock",
647: ConfigLockLevel.WRITE);
648: definition.commit();
649: config.addLock(methodExpression, definition);
650:
651: methodExpression = "* " + testClass
652: + "$NameLockUpgradeClass.doWrite(..)";
653: definition = new LockDefinitionImpl("nameLock",
654: ConfigLockLevel.WRITE);
655: definition.commit();
656: config.addLock(methodExpression, definition);
657:
658: methodExpression = "* " + testClass
659: + "$NameLockUpgradeClass.intWrite(..)";
660: definition = new LockDefinitionImpl("nameLock",
661: ConfigLockLevel.WRITE);
662: definition.commit();
663: config.addLock(methodExpression, definition);
664:
665: methodExpression = "* " + testClass
666: + "$NameLockUpgradeClass.objWrite(..)";
667: definition = new LockDefinitionImpl("nameLock",
668: ConfigLockLevel.WRITE);
669: definition.commit();
670: config.addLock(methodExpression, definition);
671:
672: methodExpression = "* " + testClass
673: + "$NameLockUpgradeClass.longWrite(..)";
674: definition = new LockDefinitionImpl("nameLock",
675: ConfigLockLevel.WRITE);
676: definition.commit();
677: config.addLock(methodExpression, definition);
678:
679: methodExpression = "* " + testClass
680: + "$NameLockUpgradeClass.doubleWrite(..)";
681: definition = new LockDefinitionImpl("nameLock",
682: ConfigLockLevel.WRITE);
683: definition.commit();
684: config.addLock(methodExpression, definition);
685:
686: methodExpression = "* " + testClass
687: + "$NameLockUpgradeClass.doWriteWithNameLock1(..)";
688: definition = new LockDefinitionImpl("nameLock1",
689: ConfigLockLevel.WRITE);
690: definition.commit();
691: config.addLock(methodExpression, definition);
692:
693: methodExpression = "* " + testClass
694: + "$NameLockUpgradeClass.intWriteWithNameLock1(..)";
695: definition = new LockDefinitionImpl("nameLock1",
696: ConfigLockLevel.WRITE);
697: definition.commit();
698: config.addLock(methodExpression, definition);
699:
700: methodExpression = "* " + testClass
701: + "$NameLockUpgradeClass.objWriteWithNameLock1(..)";
702: definition = new LockDefinitionImpl("nameLock1",
703: ConfigLockLevel.WRITE);
704: definition.commit();
705: config.addLock(methodExpression, definition);
706:
707: methodExpression = "* " + testClass
708: + "$NameLockUpgradeClass.doReadWriteOnTwoNameLock(..)";
709: definition = new LockDefinitionImpl("nameLock",
710: ConfigLockLevel.WRITE);
711: definition.commit();
712: config.addLock(methodExpression, definition);
713: definition = new LockDefinitionImpl("nameLock1",
714: ConfigLockLevel.READ);
715: definition.commit();
716: config.addLock(methodExpression, definition);
717:
718: methodExpression = "* " + testClass
719: + "$NameLockUpgradeClass.intReadWriteOnTwoNameLock(..)";
720: definition = new LockDefinitionImpl("nameLock",
721: ConfigLockLevel.WRITE);
722: definition.commit();
723: config.addLock(methodExpression, definition);
724: definition = new LockDefinitionImpl("nameLock1",
725: ConfigLockLevel.READ);
726: definition.commit();
727: config.addLock(methodExpression, definition);
728:
729: methodExpression = "* " + testClass
730: + "$NameLockUpgradeClass.objReadWriteOnTwoNameLock(..)";
731: definition = new LockDefinitionImpl("nameLock",
732: ConfigLockLevel.WRITE);
733: definition.commit();
734: config.addLock(methodExpression, definition);
735: definition = new LockDefinitionImpl("nameLock1",
736: ConfigLockLevel.READ);
737: definition.commit();
738: config.addLock(methodExpression, definition);
739:
740: new CyclicBarrierSpec().visit(visitor, config);
741:
742: }
743:
744: private static class NameLockUpgradeClass {
745: public NameLockUpgradeClass() {
746: super ();
747: }
748:
749: public void doReadWrite(CyclicBarrier barrier) throws Throwable {
750: // This method should get a name lock with read level and then write level
751: System.err.println("In doReadWrite");
752: }
753:
754: public void doWrite() {
755: // This method will get a name lock with write level only
756: System.err.println("In doWrite");
757: }
758:
759: public void doWriteWithNameLock1() {
760: // This method will get a name lock with write level only
761: System.err.println("In doWriteWithNameLock1");
762: }
763:
764: public void doThrowException(CyclicBarrier barrier)
765: throws Throwable {
766: barrier.barrier();
767: Thread.sleep(2000);
768: throw new RuntimeException("Test exception");
769: }
770:
771: public void doReadWriteOnTwoNameLock(CyclicBarrier barrier)
772: throws Throwable {
773: // This method should get a name lock with read level and then write level, but on two different name locks
774: barrier.barrier();
775: Thread.sleep(2000);
776: System.err.println("In doReadWriteOnTwoNameLock");
777: }
778:
779: public int intReadWrite(CyclicBarrier barrier) throws Throwable {
780: // This method should get a name lock with read level and then write level
781: System.err.println("In intReadWrite");
782: return 2;
783: }
784:
785: public long longReadWrite(CyclicBarrier barrier)
786: throws Throwable {
787: // This method should get a name lock with read level and then write level
788: System.err.println("In longReadWrite");
789: return Long.MAX_VALUE;
790: }
791:
792: public double doubleReadWrite(CyclicBarrier barrier)
793: throws Throwable {
794: // This method should get a name lock with read level and then write level
795: System.err.println("In doubleReadWrite");
796: return Double.MAX_VALUE;
797: }
798:
799: public Object objReadWrite(CyclicBarrier barrier)
800: throws Throwable {
801: // This method should get a name lock with read level and then write level
802: System.err.println("In objReadWrite");
803: return new Object();
804: }
805:
806: public int intWrite() {
807: // This method will get a name lock with write level only
808: System.err.println("In intWrite");
809: return 2;
810: }
811:
812: public long longWrite() {
813: System.err.println("In longWrite");
814: return Long.MAX_VALUE;
815: }
816:
817: public double doubleWrite() {
818: System.err.println("In doubleWrite");
819: return Double.MAX_VALUE;
820: }
821:
822: public Object objWrite() {
823: // This method will get a name lock with write level only
824: System.err.println("In objWrite");
825: return new Object();
826: }
827:
828: public int intThrowException(CyclicBarrier barrier)
829: throws Throwable {
830: barrier.barrier();
831: Thread.sleep(2000);
832: throw new RuntimeException("Test exception");
833: }
834:
835: public Object objThrowException(CyclicBarrier barrier)
836: throws Throwable {
837: barrier.barrier();
838: Thread.sleep(2000);
839: throw new RuntimeException("Test exception");
840: }
841:
842: public int intReadWriteOnTwoNameLock(CyclicBarrier barrier)
843: throws Throwable {
844: // This method should get a name lock with read level and then write level, but on two different name locks
845: barrier.barrier();
846: Thread.sleep(2000);
847: System.err.println("In intReadWriteOnTwoNameLock");
848: return 3;
849: }
850:
851: public Object objReadWriteOnTwoNameLock(CyclicBarrier barrier)
852: throws Throwable {
853: // This method should get a name lock with read level and then write level, but on two different name locks
854: barrier.barrier();
855: Thread.sleep(2000);
856: System.err.println("In objReadWriteOnTwoNameLock");
857: return new Object();
858: }
859:
860: public int intWriteWithNameLock1() {
861: // This method will get a name lock with write level only
862: System.err.println("In intWriteWithNameLock1");
863: return 4;
864: }
865:
866: public Object objWriteWithNameLock1() {
867: // This method will get a name lock with write level only
868: System.err.println("In objWriteWithNameLock1");
869: return new Object();
870: }
871: }
872:
873: }
|