Skip to content

Commit

Permalink
[hotfix] Refactor the setup function of KubernetesTestBase
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmaGYZ authored and tillrohrmann committed May 17, 2020
1 parent a06b1bb commit 6075ed7
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
import io.fabric8.kubernetes.api.model.ServiceStatus;
import io.fabric8.kubernetes.api.model.ServiceStatusBuilder;
import org.junit.Before;

import javax.annotation.Nullable;

Expand All @@ -45,11 +44,6 @@ public class KubernetesClientTestBase extends KubernetesTestBase {
protected static final int REST_PORT = 9021;
protected static final int NODE_PORT = 31234;

@Before
public void setup() throws Exception {
super.setup();
}

protected void mockExpectedServiceFromServerSide(Service expectedService) {
final String serviceName = expectedService.getMetadata().getName();
final String path = String.format("/api/v1/namespaces/%s/services/%s", NAMESPACE, serviceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -66,9 +65,9 @@ public class KubernetesClusterDescriptorTest extends KubernetesClientTestBase {

private KubernetesClusterDescriptor descriptor;

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

descriptor = new KubernetesClusterDescriptor(flinkConfig, flinkKubeClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -122,9 +121,9 @@ protected void setupFlinkConfig() {
flinkConfig.setString(TaskManagerOptions.RPC_PORT, String.valueOf(Constants.TASK_MANAGER_RPC_PORT));
}

@Before
public void setup() throws Exception {
super.setup();
@Override
public void onSetup() throws Exception {
super.onSetup();

final Deployment mockDeployment = new DeploymentBuilder()
.editOrNewMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ protected void setupFlinkConfig() {
flinkConfig.set(JobManagerOptions.TOTAL_PROCESS_MEMORY, MemorySize.ofMebiBytes(JOB_MANAGER_MEMORY));
}

protected void onSetup() throws Exception {
}

@Before
public void setup() throws Exception {
public final void setup() throws Exception {
setupFlinkConfig();

flinkConfDir = temporaryFolder.newFolder().getAbsoluteFile();
Expand All @@ -94,6 +97,8 @@ public void setup() throws Exception {

kubeClient = server.getClient().inNamespace(NAMESPACE);
flinkKubeClient = new Fabric8FlinkKubeClient(flinkConfig, kubeClient, Executors::newDirectExecutorService);

onSetup();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import org.junit.Before;
import org.junit.Test;

import java.util.List;
Expand Down Expand Up @@ -83,9 +82,9 @@ protected void setupFlinkConfig() {
flinkConfig.set(KubernetesConfigOptions.JOB_MANAGER_SERVICE_ACCOUNT, SERVICE_ACCOUNT_NAME);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "logback.xml");
KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "log4j.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
import org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters;

import org.junit.Before;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -87,10 +85,8 @@ protected void setupFlinkConfig() {
this.flinkConfig.set(JobManagerOptions.TOTAL_PROCESS_MEMORY, MemorySize.ofMebiBytes(JOB_MANAGER_MEMORY));
}

@Before
public void setup() throws Exception {
super.setup();

@Override
protected void onSetup() throws Exception {
final ClusterSpecification clusterSpecification = new ClusterSpecification.ClusterSpecificationBuilder()
.setMasterMemoryMB(JOB_MANAGER_MEMORY)
.setTaskManagerMemoryMB(1024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec;
import org.apache.flink.runtime.clusterframework.TaskExecutorProcessUtils;

import org.junit.Before;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -88,10 +86,8 @@ protected void setupFlinkConfig() {
this.flinkConfig.set(KubernetesConfigOptions.TASK_MANAGER_NODE_SELECTOR, nodeSelector);
}

@Before
public void setup() throws Exception {
super.setup();

@Override
protected void onSetup() throws Exception {
taskExecutorProcessSpec = TaskExecutorProcessUtils.processSpecFromConfig(flinkConfig);
containeredTaskManagerParameters = ContaineredTaskManagerParameters.create(flinkConfig, taskExecutorProcessSpec);
kubernetesTaskManagerParameters = new KubernetesTaskManagerParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -55,9 +54,9 @@ public class ExternalServiceDecoratorTest extends KubernetesJobManagerTestBase {
}
};

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

this.flinkConfig.set(KubernetesConfigOptions.REST_SERVICE_ANNOTATIONS, customizedAnnotations);
this.externalServiceDecorator = new ExternalServiceDecorator(this.kubernetesJobManagerParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.fabric8.kubernetes.api.model.VolumeBuilder;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -63,9 +62,9 @@ protected void setupFlinkConfig() {
this.flinkConfig.set(KubernetesConfigOptions.FLINK_CONF_DIR, FLINK_CONF_DIR_IN_POD);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

this.flinkConfMountDecorator = new FlinkConfMountDecorator(kubernetesJobManagerParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.fabric8.kubernetes.api.model.KeyToPath;
import io.fabric8.kubernetes.api.model.Volume;
import io.fabric8.kubernetes.api.model.VolumeMount;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -52,9 +51,10 @@ public class HadoopConfMountDecoratorTest extends KubernetesJobManagerTestBase {

private HadoopConfMountDecorator hadoopConfMountDecorator;

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

this.hadoopConfMountDecorator = new HadoopConfMountDecorator(kubernetesJobManagerParameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.fabric8.kubernetes.api.model.ResourceRequirements;
import io.fabric8.kubernetes.api.model.Toleration;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -81,9 +80,9 @@ protected void setupFlinkConfig() {
this.flinkConfig.setString(KubernetesConfigOptions.JOB_MANAGER_TOLERATIONS.key(), TOLERATION_STRING);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

final InitJobManagerDecorator initJobManagerDecorator =
new InitJobManagerDecorator(this.kubernetesJobManagerParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.fabric8.kubernetes.api.model.ResourceRequirements;
import io.fabric8.kubernetes.api.model.Toleration;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -78,9 +77,9 @@ protected void setupFlinkConfig() {
this.flinkConfig.setString(KubernetesConfigOptions.TASK_MANAGER_TOLERATIONS.key(), TOLERATION_STRING);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

final InitTaskManagerDecorator initTaskManagerDecorator =
new InitTaskManagerDecorator(kubernetesTaskManagerParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -47,9 +46,10 @@ public class InternalServiceDecoratorTest extends KubernetesJobManagerTestBase {

private InternalServiceDecorator internalServiceDecorator;

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

this.internalServiceDecorator = new InternalServiceDecorator(this.kubernetesJobManagerParameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.flink.runtime.util.config.memory.ProcessMemoryUtils;

import io.fabric8.kubernetes.api.model.Container;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -80,9 +79,9 @@ protected void setupFlinkConfig() {
flinkConfig.set(KubernetesConfigOptions.KUBERNETES_ENTRY_PATH, KUBERNETES_ENTRY_PATH);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

this.javaCmdJobManagerDecorator = new JavaCmdJobManagerDecorator(kubernetesJobManagerParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.flink.runtime.clusterframework.TaskExecutorProcessUtils;

import io.fabric8.kubernetes.api.model.Container;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -80,9 +79,9 @@ protected void setupFlinkConfig() {
flinkConfig.set(KubernetesConfigOptions.FLINK_LOG_DIR, FLINK_LOG_DIR_IN_POD);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
public void onSetup() throws Exception {
super.onSetup();

this.mainClassArgs = String.format(
"%s--configDir %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentSpec;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -74,9 +73,9 @@ protected void setupFlinkConfig() {
flinkConfig.set(KubernetesConfigOptions.JOB_MANAGER_SERVICE_ACCOUNT, SERVICE_ACCOUNT_NAME);
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "logback.xml");
KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "log4j.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.Pod;
import org.junit.Before;
import org.junit.Test;

import java.util.List;
Expand All @@ -39,9 +38,9 @@ public class KubernetesTaskManagerFactoryTest extends KubernetesTaskManagerTestB

private Pod resultPod;

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "logback.xml");
KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "log4j.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec;
import org.apache.flink.runtime.clusterframework.TaskExecutorProcessUtils;

import org.junit.Before;
import org.junit.Test;

import java.util.HashMap;
Expand Down Expand Up @@ -73,9 +72,9 @@ protected void setupFlinkConfig() {
flinkConfig.setString(ResourceManagerOptions.CONTAINERIZED_TASK_MANAGER_ENV_PREFIX + k, v));
}

@Before
public void setup() throws Exception {
super.setup();
@Override
protected void onSetup() throws Exception {
super.onSetup();

final TaskExecutorProcessSpec taskExecutorProcessSpec =
TaskExecutorProcessUtils.processSpecFromConfig(flinkConfig);
Expand Down

0 comments on commit 6075ed7

Please sign in to comment.