01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest.server.appserver.unit;
06:
07: import com.meterware.httpunit.WebConversation;
08: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
09: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
10: import com.tc.test.server.appserver.deployment.WebApplicationServer;
11: import com.tc.test.server.util.TcConfigBuilder;
12: import com.tctest.webapp.servlets.SynchronousWriteTestServlet;
13:
14: import junit.framework.Test;
15:
16: /**
17: * Test session with synchronous-write
18: */
19: public class SynchronousWriteTest extends
20: AbstractTwoServerDeploymentTest {
21: private static final String CONTEXT = "SynchronousWriteTest";
22: private static final String SERVLET = "SynchronousWriteTestServlet";
23:
24: private static final int INTENSITY = 100;
25:
26: public static Test suite() {
27: return new SynchronousWriteTestSetup();
28: }
29:
30: public void testSynchWrite() throws Exception {
31: WebConversation wc = new WebConversation();
32: createTransactions(server0, wc);
33: assertEquals("99", request(server1, "server=1&data=99", wc));
34: }
35:
36: private void createTransactions(WebApplicationServer server,
37: WebConversation wc) throws Exception {
38: for (int i = 0; i < INTENSITY; i++) {
39: assertEquals("OK",
40: request(server, "server=0&data=" + i, wc));
41: }
42: }
43:
44: private String request(WebApplicationServer server, String params,
45: WebConversation con) throws Exception {
46: return server.ping(
47: "/" + CONTEXT + "/" + SERVLET + "?" + params, con)
48: .getText().trim();
49: }
50:
51: private static class SynchronousWriteTestSetup extends
52: TwoServerTestSetup {
53:
54: public SynchronousWriteTestSetup() {
55: super (SynchronousWriteTest.class, CONTEXT);
56: }
57:
58: protected void configureWar(DeploymentBuilder builder) {
59: builder.addServlet(SERVLET, "/" + SERVLET + "/*",
60: SynchronousWriteTestServlet.class, null, false);
61: }
62:
63: protected void configureTcConfig(TcConfigBuilder clientConfig) {
64: clientConfig.addWebApplication(CONTEXT, true);
65: }
66: }
67: }
|