|
| 1 | +// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Universal Permissive License v 1.0 as shown at |
| 3 | +// http://oss.oracle.com/licenses/upl. |
| 4 | + |
| 5 | +package oracle.kubernetes.operator; |
| 6 | + |
| 7 | +import java.nio.file.Files; |
| 8 | +import java.nio.file.Paths; |
| 9 | +import java.util.Map; |
| 10 | +import oracle.kubernetes.operator.utils.CoherenceUtils; |
| 11 | +import oracle.kubernetes.operator.utils.Domain; |
| 12 | +import oracle.kubernetes.operator.utils.ExecResult; |
| 13 | +import oracle.kubernetes.operator.utils.K8sTestUtils; |
| 14 | +import oracle.kubernetes.operator.utils.Operator; |
| 15 | +import oracle.kubernetes.operator.utils.TestUtils; |
| 16 | +import org.junit.AfterClass; |
| 17 | +import org.junit.Assert; |
| 18 | +import org.junit.Assume; |
| 19 | +import org.junit.BeforeClass; |
| 20 | +import org.junit.FixMethodOrder; |
| 21 | +import org.junit.Ignore; |
| 22 | +import org.junit.Test; |
| 23 | +import org.junit.runners.MethodSorters; |
| 24 | +/** |
| 25 | + * Simple JUnit test file used for testing Operator. |
| 26 | + * |
| 27 | + * <p>This test is used for testing pods being restarted by some properties change. |
| 28 | + */ |
| 29 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 30 | +public class ITCoherenceTests extends BaseTest { |
| 31 | + |
| 32 | + private static Domain domain = null; |
| 33 | + private static Operator operator1; |
| 34 | + private static String domainUid = ""; |
| 35 | + private static String restartTmpDir = ""; |
| 36 | + private static String originalYaml; |
| 37 | + |
| 38 | + /** |
| 39 | + * This method gets called only once before any of the test methods are executed. It does the |
| 40 | + * initialization of the integration test properties defined in OperatorIT.properties and setting |
| 41 | + * the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST |
| 42 | + * with admin server and 1 managed server if they are not running |
| 43 | + * |
| 44 | + * @throws Exception |
| 45 | + */ |
| 46 | + @BeforeClass |
| 47 | + public static void staticPrepare() throws Exception { |
| 48 | + // initialize test properties and create the directories |
| 49 | + if (!QUICKTEST) { |
| 50 | + initialize(APP_PROPS_FILE); |
| 51 | + |
| 52 | + if (operator1 == null) { |
| 53 | + operator1 = TestUtils.createOperator(OPERATOR1_YAML); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Releases k8s cluster lease, archives result, pv directories |
| 60 | + * |
| 61 | + * @throws Exception |
| 62 | + */ |
| 63 | + @AfterClass |
| 64 | + public static void staticUnPrepare() throws Exception { |
| 65 | + if (!QUICKTEST) { |
| 66 | + tearDown(new Object() {}.getClass().getEnclosingClass().getSimpleName()); |
| 67 | + logger.info("SUCCESS"); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testRollingRestart() throws Exception { |
| 73 | + |
| 74 | + CoherenceUtils utils = new CoherenceUtils(); |
| 75 | + |
| 76 | + domain = createDomain(); |
| 77 | + Assert.assertNotNull(domain); |
| 78 | + |
| 79 | + // public static void exposePod(String podName, String domainNS, String serviceName, int port, |
| 80 | + // int targetPort) throws Exception { |
| 81 | + |
| 82 | + |
| 83 | +// String nodePortName = "coh-nodeport"; |
| 84 | +// String podName = "dd"; |
| 85 | +// int port = 9000; |
| 86 | +// TestUtils.exposePod(podName, domain.getDomainNS(), nodePortName, port, port); |
| 87 | +// |
| 88 | + utils.loadCache(); |
| 89 | + utils.validateCache(); |
| 90 | + |
| 91 | + destroyDomain(); |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + /** |
| 96 | + * Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml |
| 97 | + * Verify that all the server pods in the domain got re-started. The property tested is: env: |
| 98 | + * "-Dweblogic.StdoutDebugEnabled=false"--> "-Dweblogic.StdoutDebugEnabled=true" |
| 99 | + * |
| 100 | + * @throws Exception |
| 101 | + */ |
| 102 | + @Ignore |
| 103 | + @Test |
| 104 | + public void testServerPodsRestartByChangingEnvProperty() throws Exception { |
| 105 | + |
| 106 | + |
| 107 | + Assume.assumeFalse(QUICKTEST); |
| 108 | + String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName(); |
| 109 | + logTestBegin(testMethodName); |
| 110 | + |
| 111 | + logger.info( |
| 112 | + "About to verifyDomainServerPodRestart for Domain: " |
| 113 | + + domain.getDomainUid() |
| 114 | + + " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true"); |
| 115 | + domain.verifyDomainServerPodRestart( |
| 116 | + "\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\""); |
| 117 | + |
| 118 | + logger.info("SUCCESS - " + testMethodName); |
| 119 | + } |
| 120 | + |
| 121 | + private static Domain createDomain() throws Exception { |
| 122 | + |
| 123 | + Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WLST_YAML); |
| 124 | + domainMap.put("namespace","test1"); |
| 125 | + domainMap.put("domainUID", "coh"); |
| 126 | + domain = TestUtils.createDomain(domainMap); |
| 127 | + domain.verifyDomainCreated(); |
| 128 | + return domain; |
| 129 | + } |
| 130 | + |
| 131 | + private static void destroyDomain() throws Exception { |
| 132 | + if (domain != null) { |
| 133 | + domain.destroy(); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Utility method to check if a pod is in Terminating or Running status |
| 139 | + * |
| 140 | + * @param podName - String name of the pod to check the status for |
| 141 | + * @param podStatusExpected - String the expected status of Terminating || RUnning |
| 142 | + * @throws InterruptedException when thread is interrupted |
| 143 | + */ |
| 144 | + private void verifyPodStatus(String podName, String podStatusExpected) |
| 145 | + throws InterruptedException { |
| 146 | + K8sTestUtils testUtil = new K8sTestUtils(); |
| 147 | + String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUid); |
| 148 | + String namespace = domain.getDomainNS(); |
| 149 | + boolean gotExpected = false; |
| 150 | + for (int i = 0; i < BaseTest.getMaxIterationsPod(); i++) { |
| 151 | + if (podStatusExpected.equals("Terminating")) { |
| 152 | + if (testUtil.isPodTerminating(namespace, domain1LabelSelector, podName)) { |
| 153 | + gotExpected = true; |
| 154 | + break; |
| 155 | + } |
| 156 | + } else if (podStatusExpected.equals("Running")) { |
| 157 | + if (testUtil.isPodRunning(namespace, domain1LabelSelector, podName)) { |
| 158 | + gotExpected = true; |
| 159 | + break; |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + Thread.sleep(BaseTest.getWaitTimePod() * 1000); |
| 164 | + } |
| 165 | + Assert.assertTrue("Didn't get the expected pod status", gotExpected); |
| 166 | + } |
| 167 | +} |
0 commit comments