Source Code Cross Referenced for SharedLockTest.java in  » Net » Terracotta » com » tctest » spring » integrationtests » tests » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tctest.spring.integrationtests.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.spring.integrationtests.tests;
006:
007:        import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
008:        import com.tc.test.server.appserver.deployment.DeploymentBuilder;
009:        import com.tctest.spring.bean.ISharedLock;
010:        import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
011:
012:        import junit.framework.Test;
013:
014:        /**
015:         * This class is testing shared lock behavior
016:         *
017:         * <ol>
018:         * <li> Trying to modify a shared object outside a shared lock should raise exception
019:         * <li> Locking on shared object applies to the whole cluster
020:         * <li> Shared value will not be propagated until execution thread exits the monitor
021:         * </ol>
022:         */
023:        public class SharedLockTest extends AbstractTwoServerDeploymentTest {
024:
025:            private static final String REMOTE_SERVICE_NAME = "SharedLock";
026:            private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-sharedlock.xml";
027:            private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/sharedlock-tc-config.xml";
028:
029:            private ISharedLock sharedLock1;
030:            private ISharedLock sharedLock2;
031:
032:            protected void setUp() throws Exception {
033:                super .setUp();
034:
035:                sharedLock1 = (ISharedLock) server0.getProxy(ISharedLock.class,
036:                        REMOTE_SERVICE_NAME);
037:                sharedLock2 = (ISharedLock) server1.getProxy(ISharedLock.class,
038:                        REMOTE_SERVICE_NAME);
039:            }
040:
041:            public void testSharedLock() throws Exception {
042:                logger.debug("testing ShareLock");
043:
044:                long id1 = sharedLock1.getLocalID();
045:                long id2 = sharedLock2.getLocalID();
046:
047:                assertTrue("Pre-condition is not satisfied - id1 - " + id1
048:                        + " - id2 - " + id2, id1 != id2);
049:
050:                // test mutation w/o a lock
051:                sharedLock1.unlockedMutate();
052:                sharedLock2.unlockedMutate();
053:
054:                LockAndMutate t1 = new LockAndMutate(sharedLock1);
055:                LockAndMutate t2 = new LockAndMutate(sharedLock2);
056:                t1.start();
057:                t2.start();
058:
059:                LockAndMutate loser = null;
060:                LockAndMutate winner = null;
061:                while (true) {
062:                    if (t1.wasFirst()) {
063:                        winner = t1;
064:                        break;
065:                    } else if (t2.wasFirst()) {
066:                        winner = t2;
067:                        break;
068:                    } else {
069:                        Thread.sleep(250);
070:                    }
071:                }
072:
073:                loser = (winner == t1) ? t2 : t1;
074:                assertNotSame(winner, loser);
075:
076:                // This sleep is unnecessary, but just used to help ferret out false positives
077:                Thread.sleep(5000);
078:
079:                assertFalse(loser.wasFirst());
080:                assertTrue(winner.sharedLockHeld());
081:                assertFalse(loser.sharedLockHeld());
082:                assertNull(loser.getFirstHolder()); // This will be null for the loser since the winner has not yet committed
083:
084:                winner.release();
085:
086:                t1.join();
087:                t2.join();
088:
089:                assertEquals(new Long(winner.getLocalID()), loser
090:                        .getFirstHolder());
091:
092:                logger.debug("!!!! Asserts passed !!!");
093:            }
094:
095:            private static class LockAndMutate extends Thread {
096:
097:                private final ISharedLock lock;
098:
099:                LockAndMutate(ISharedLock lock) {
100:                    this .lock = lock;
101:                }
102:
103:                public void run() {
104:                    lock.lockAndMutate();
105:                }
106:
107:                Long getFirstHolder() {
108:                    return lock.getFirstHolder();
109:                }
110:
111:                boolean wasFirst() {
112:                    return lock.isFirstHolder();
113:                }
114:
115:                boolean sharedLockHeld() {
116:                    return lock.sharedLockHeld();
117:                }
118:
119:                void release() {
120:                    lock.release();
121:                }
122:
123:                long getLocalID() {
124:                    return lock.getLocalID();
125:                }
126:
127:            }
128:
129:            private static class SharedLockTestSetup extends
130:                    SpringTwoServerTestSetup {
131:                private SharedLockTestSetup() {
132:                    super (SharedLockTest.class, CONFIG_FILE_FOR_TEST,
133:                            "test-sharedlock");
134:                }
135:
136:                protected void configureWar(DeploymentBuilder builder) {
137:                    builder
138:                            .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
139:                    builder.addRemoteService(REMOTE_SERVICE_NAME, "sharedlock",
140:                            ISharedLock.class);
141:                }
142:            }
143:
144:            public static Test suite() {
145:                return new SharedLockTestSetup();
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.