Source Code Cross Referenced for MaxConnectionTest.java in  » Net » Terracotta » com » tctest » 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 
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;
006:
007:        import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
008:
009:        import com.tc.cluster.Cluster;
010:        import com.tc.config.schema.setup.L1TVSConfigurationSetupManager;
011:        import com.tc.config.schema.setup.L2TVSConfigurationSetupManager;
012:        import com.tc.config.schema.setup.TestTVSConfigurationSetupManagerFactory;
013:        import com.tc.exception.TCRuntimeException;
014:        import com.tc.lang.TCThreadGroup;
015:        import com.tc.lang.ThrowableHandler;
016:        import com.tc.logging.TCLogging;
017:        import com.tc.net.protocol.transport.ConnectionPolicy;
018:        import com.tc.net.protocol.transport.ConnectionPolicyImpl;
019:        import com.tc.object.BaseDSOTestCase;
020:        import com.tc.object.DistributedObjectClient;
021:        import com.tc.object.bytecode.MockClassProvider;
022:        import com.tc.object.bytecode.NullManager;
023:        import com.tc.object.bytecode.hook.impl.PreparedComponentsFromL2Connection;
024:        import com.tc.object.config.DSOClientConfigHelper;
025:        import com.tc.object.config.StandardDSOClientConfigHelperImpl;
026:        import com.tc.server.TCServerImpl;
027:        import com.tc.util.concurrent.ThreadUtil;
028:
029:        /**
030:         * Test to make sure that the maximum number of connected DSO clients may be limited. This isn't a transparency test,
031:         * but it is a system test which is why it's in the com.tctest package. It could, perhaps, be moved somewhere more
032:         * appropriate.
033:         */
034:        public class MaxConnectionTest extends BaseDSOTestCase {
035:
036:            private TCServerImpl server;
037:
038:            private DistributedObjectClient newClient() throws Exception {
039:                L1TVSConfigurationSetupManager manager = super 
040:                        .createL1ConfigManager();
041:                DSOClientConfigHelper configHelper = new StandardDSOClientConfigHelperImpl(
042:                        manager);
043:
044:                PreparedComponentsFromL2Connection components = new PreparedComponentsFromL2Connection(
045:                        manager);
046:                return new DistributedObjectClient(configHelper,
047:                        new TCThreadGroup(new ThrowableHandler(TCLogging
048:                                .getLogger(DistributedObjectClient.class))),
049:                        new MockClassProvider(), components, NullManager
050:                                .getInstance(), new Cluster());
051:            }
052:
053:            public void testsMaxConnectionLimitAndClientDisconnectAccounting()
054:                    throws Exception {
055:
056:                ConnectionPolicy connectionPolicy = new ConnectionPolicyImpl(2);
057:                TestTVSConfigurationSetupManagerFactory factory = createDistributedConfigFactory();
058:                L2TVSConfigurationSetupManager l2Manager = factory
059:                        .createL2TVSConfigurationSetupManager(null);
060:                server = new TCServerImpl(l2Manager, new TCThreadGroup(
061:                        new ThrowableHandler(TCLogging
062:                                .getLogger(TCServerImpl.class))),
063:                        connectionPolicy);
064:                server.start();
065:
066:                makeClientUsePort(server.getDSOListenPort());
067:
068:                DistributedObjectClient client1 = newClient();
069:
070:                client1.start();
071:                newClient().start();
072:
073:                final boolean[] done = new boolean[] { false };
074:
075:                new Thread() {
076:                    public void run() {
077:                        try {
078:                            newClient().start();
079:                            if (!done[0])
080:                                fail("Expected a MaxConnectionsExceededException");
081:                            else
082:                                System.out
083:                                        .println("proceeded now that someone was killed");
084:                        } catch (Exception e) {
085:                            throw new AssertionError("oops");
086:                        }
087:                    }
088:                }.start();// with the maximum number of clients connected, make sure that a new client can't connect.
089:
090:                // disconnect one of the clients
091:                LinkedQueue stopQueue = new LinkedQueue();
092:                long timeout = 5 * 1000;
093:                ThreadUtil.reallySleep(3000);
094:                done[0] = true;
095:                new Thread(new ClientStopper(stopQueue, client1)).start();
096:                if (stopQueue.poll(timeout) == null) {
097:                    fail("Client failed to stop within timeout: " + timeout
098:                            + " ms.");
099:                }
100:
101:            }
102:
103:            private static final class ClientStopper implements  Runnable {
104:                private final LinkedQueue queue;
105:                private final DistributedObjectClient myClient;
106:
107:                private ClientStopper(LinkedQueue queue,
108:                        DistributedObjectClient client) {
109:                    this .queue = queue;
110:                    this .myClient = client;
111:                }
112:
113:                public void run() {
114:                    myClient.stop();
115:                    try {
116:                        queue.put(new Object());
117:                    } catch (InterruptedException e) {
118:                        throw new TCRuntimeException(e);
119:                    }
120:                }
121:            }
122:
123:            public void tearDown() throws Exception {
124:                if (server != null) {
125:                    server.stop();
126:                }
127:            }
128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.