-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
AbstractSessionActivationTestCase.java
112 lines (91 loc) · 4.28 KB
/
AbstractSessionActivationTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.clustering.cluster.web;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.clustering.cluster.AbstractClusteringTestCase;
import org.jboss.as.test.clustering.cluster.web.event.SessionActivationServlet;
import org.jboss.as.test.http.util.TestHttpClientUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
public abstract class AbstractSessionActivationTestCase extends AbstractClusteringTestCase {
private final boolean transactional;
protected AbstractSessionActivationTestCase(boolean transactional) {
super(THREE_NODES);
this.transactional = transactional;
}
@Test
public void test(
@ArquillianResource(SessionActivationServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1,
@ArquillianResource(SessionActivationServlet.class) @OperateOnDeployment(DEPLOYMENT_2) URL baseURL2,
@ArquillianResource(SessionActivationServlet.class) @OperateOnDeployment(DEPLOYMENT_3) URL baseURL3) throws Exception {
URI uri1 = SessionActivationServlet.createURI(baseURL1);
URI uri2 = SessionActivationServlet.createURI(baseURL2);
URI uri3 = SessionActivationServlet.createURI(baseURL3);
try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
// Verify all operations on primary owner
this.execute(client, new HttpPut(uri1), false);
this.execute(client, new HttpGet(uri1), false);
this.execute(client, new HttpDelete(uri1), false);
// Verify all operations on both backup owner and non-owner
this.execute(client, new HttpPut(uri2), true);
this.execute(client, new HttpGet(uri2), false);
this.execute(client, new HttpDelete(uri2), false);
this.execute(client, new HttpPut(uri3), true);
this.execute(client, new HttpGet(uri3), false);
this.execute(client, new HttpDelete(uri3), false);
}
}
private void execute(HttpClient client, HttpUriRequest request, boolean failover) throws IOException {
if (failover && !this.transactional) {
try {
Thread.sleep(GRACE_TIME_TO_REPLICATE);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
HttpResponse response = client.execute(request);
try {
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
} finally {
HttpClientUtils.closeQuietly(response);
}
}
}