10
10
import java .util .regex .Pattern ;
11
11
12
12
import oracle .kubernetes .operator .utils .Domain ;
13
- import oracle .kubernetes .operator .utils .ExecCommand ;
14
13
import oracle .kubernetes .operator .utils .ExecResult ;
15
14
import oracle .kubernetes .operator .utils .Operator ;
16
15
import oracle .kubernetes .operator .utils .TestUtils ;
31
30
public class ItSessionMigration extends BaseTest {
32
31
private static final String testAppName = "httpsessionreptestapp" ;
33
32
private static final String scriptName = "buildDeployAppInPod.sh" ;
34
-
35
33
private static Map <String , String > httpAttrMap ;
36
-
37
34
private static String httpHeaderFile ;
38
-
39
35
private static Operator operator ;
40
36
private static Domain domain ;
41
37
@@ -71,7 +67,6 @@ public static void staticPrepare() throws Exception {
71
67
}
72
68
73
69
httpHeaderFile = BaseTest .getResultDir () + "/headers" ;
74
-
75
70
httpAttrMap = new HashMap <String , String >();
76
71
httpAttrMap .put ("sessioncreatetime" , "(.*)sessioncreatetime>(.*)</sessioncreatetime(.*)" );
77
72
httpAttrMap .put ("sessionid" , "(.*)sessionid>(.*)</sessionid(.*)" );
@@ -134,7 +129,7 @@ public void testRepickPrimary() throws Exception {
134
129
String sessCreateTime1 = getHttpResponseAttribute (result .stdout (), sessCreateTime );
135
130
136
131
// Stop primary server
137
- stopPrimaryServer (primaryServName1 );
132
+ domain . shutdownManagedServerUsingServerStartPolicy (primaryServName1 );
138
133
139
134
// Send the second HTTP request using HTTP header/sessionID info save before
140
135
result = getHttpResponse (testAppPath , " -b " );
@@ -152,6 +147,7 @@ public void testRepickPrimary() throws Exception {
152
147
primaryServName1 .trim ().equals (primaryServName2 .trim ()));
153
148
154
149
// Restore test env
150
+ domain .restartManagedServerUsingServerStartPolicy (primaryServName1 );
155
151
TestUtils .checkPodReady (domainUid + "-" + primaryServName1 , domainNS );
156
152
157
153
logger .info (
@@ -190,7 +186,7 @@ public void testHttpSessionMigr() throws Exception {
190
186
final String countattribute1 = getHttpResponseAttribute (result .stdout (), count );
191
187
192
188
// Stop primary server
193
- stopPrimaryServer (primaryServName1 );
189
+ domain . shutdownManagedServerUsingServerStartPolicy (primaryServName1 );
194
190
195
191
// Send the second HTTP request using HTTP header/sessionID info save before
196
192
result = getHttpResponse (webServiceGetUrl , " -b " );
@@ -210,6 +206,7 @@ public void testHttpSessionMigr() throws Exception {
210
206
"HTTP session state is NOT migrated!" , countattribute1 .equals (countattribute2 ));
211
207
212
208
// Restore test env
209
+ domain .restartManagedServerUsingServerStartPolicy (primaryServName1 );
213
210
TestUtils .checkPodReady (domainUid + "-" + primaryServName1 , domainNS );
214
211
215
212
logger .info ("SUCCESS - " + testMethodName + ". HTTP session state is migrated!" );
@@ -227,59 +224,22 @@ private ExecResult getHttpResponse(String webServiceUrl, String headerOption) th
227
224
String curlCmd = buildWebServiceUrl (webServiceUrl , headerOption + httpHeaderFile );
228
225
logger .info ("Send a HTTP request: " + curlCmd );
229
226
230
- ExecResult result = ExecCommand .exec (curlCmd );
231
-
232
- if (result .exitValue () != 0 ) {
233
- throw new Exception (
234
- "FAILURE: command "
235
- + curlCmd
236
- + " failed, returned "
237
- + result .stderr ()
238
- + "\n "
239
- + result .stdout ());
240
- }
227
+ ExecResult result = TestUtils .exec (curlCmd );
241
228
242
229
return result ;
243
230
}
244
231
245
- /**
246
- * Stop the primary server.
247
- *
248
- * @param primaryServerName - weblogic primary server name
249
- * @throws Exception exception
250
- */
251
- private void stopPrimaryServer (String primaryServerName ) throws Exception {
252
- Map <String , Object > domainMap = domain .getDomainMap ();
253
- String domainNS = domainMap .get ("namespace" ).toString ();
254
- String domainUid = domain .getDomainUid ();
255
-
256
- // stop primary server
257
- String msPodName = domainUid + "-" + primaryServerName ;
258
- String cmd = "kubectl delete po/" + msPodName + " -n " + domainNS ;
259
- logger .info ("Stop managed server <" + msPodName + "> using command:\n " + cmd );
260
-
261
- ExecResult result = ExecCommand .exec (cmd );
262
- if (result .exitValue () != 0 ) {
263
- throw new Exception ("FAILURE: command " + cmd + " failed, returned " + result .stderr ());
264
- }
265
-
266
- logger .info (result .stdout ());
267
- }
268
-
269
232
/**
270
233
* Get the value of a HTTP attribute.
271
234
*
272
235
* @param httpResponseString - HTTP response
273
- * @param attribute - attrubute name to find in the HTTP response
236
+ * @param attribute - attribute name to find in the HTTP response
274
237
* @throws Exception exception
275
238
*/
276
239
private String getHttpResponseAttribute (String httpResponseString , String attribute )
277
240
throws Exception {
278
-
279
241
String attrPatn = httpAttrMap .get (attribute );
280
-
281
242
Assume .assumeNotNull (attrPatn );
282
-
283
243
String httpAttribute = null ;
284
244
285
245
Pattern pattern = Pattern .compile (attrPatn );
@@ -317,28 +277,4 @@ private String buildWebServiceUrl(String curlUrlPath, String paramToAppend) thro
317
277
318
278
return webServiceUrl .toString ();
319
279
}
320
-
321
- /**
322
- * Execute a given curl command and verify the results.
323
- *
324
- * @param curlCmd - a curl command to execute
325
- * @throws Exception exception
326
- */
327
- private ExecResult execCurlCmd (String curlCmd ) throws Exception {
328
- logger .info ("curl command to exec is:\n " + curlCmd );
329
-
330
- ExecResult result = ExecCommand .exec (curlCmd );
331
-
332
- if (result .exitValue () != 0 ) {
333
- throw new Exception (
334
- "FAILURE: command "
335
- + curlCmd
336
- + " failed, returned "
337
- + result .stderr ()
338
- + "\n "
339
- + result .stdout ());
340
- }
341
-
342
- return result ;
343
- }
344
280
}
0 commit comments