Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
tests: test to exercise emulated k8s cluster code
Browse files Browse the repository at this point in the history
Signed-off-by: Lalith Suresh <[email protected]>
  • Loading branch information
lalithsuresh committed Nov 1, 2020
1 parent b8386dd commit 8e481b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
26 changes: 15 additions & 11 deletions k8s-scheduler/src/main/java/com/vmware/dcm/EmulatedCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void runTraceLocally(final int numNodes, final String traceFileName, fina
final IPodDeployer deployer = new EmulatedPodDeployer(handler, "default");
final DefaultKubernetesClient client = new DefaultKubernetesClient();
traceReplayer.runTrace(client, traceFileName, deployer, "dcm-scheduler", cpuScaleDown,
memScaleDown, timeScaleDown, startTimeCutOff, affinityRequirementsProportion);
memScaleDown, timeScaleDown, startTimeCutOff, affinityRequirementsProportion, 5);
}

private static Node addNode(final String nodeName, final Map<String, String> labels,
Expand Down Expand Up @@ -152,22 +152,22 @@ private static Pod newPod(final String podName, final String phase, final Map<St
return pod;
}

public static void main(final String[] args) throws Exception {
public static void runWorkload(final String[] args) throws Exception {
final EmulatedCluster emulatedCluster = new EmulatedCluster();
final Options options = new Options();

options.addRequiredOption("n", "numNodes", true,
"Number of nodes in experiment");
"Number of nodes in experiment");
options.addRequiredOption("f", "traceFile", true,
"Trace file to use from k8s-scheduler/src/test/resources/");
"Trace file to use from k8s-scheduler/src/test/resources/");
options.addRequiredOption("c", "cpuScaleDown", true,
"Factor by which to scale down CPU resource demands for pods");
"Factor by which to scale down CPU resource demands for pods");
options.addRequiredOption("m", "memScaleDown", true,
"Factor by which to scale down Memory resource demands for pods");
"Factor by which to scale down Memory resource demands for pods");
options.addRequiredOption("t", "timeScaleDown", true,
"Factor by which to scale down arrival rate for pods");
"Factor by which to scale down arrival rate for pods");
options.addRequiredOption("s", "startTimeCutOff", true,
"N, where we replay first N seconds of trace");
"N, where we replay first N seconds of trace");
options.addOption("p", "proportion", true,
"P, from 0 to 100, indicating the proportion of pods that have affinity requirements");
final CommandLineParser parser = new DefaultParser();
Expand All @@ -179,14 +179,18 @@ public static void main(final String[] args) throws Exception {
final int timeScaleDown = Integer.parseInt(cmd.getOptionValue("timeScaleDown"));
final int startTimeCutOff = Integer.parseInt(cmd.getOptionValue("startTimeCutOff"));
final int affinityRequirementsProportion = Integer.parseInt(cmd.hasOption("proportion") ?
cmd.getOptionValue("proportion") : "0");
cmd.getOptionValue("proportion") : "0");
assert affinityRequirementsProportion >= 0 && affinityRequirementsProportion <= 100;
LOG.info("Running experiment with parameters: numNodes: {}, traceFile: {}, cpuScaleDown: {}, " +
"memScaleDown: {}, timeScaleDown: {}, startTimeCutOff: {}, proportion: {}",
"memScaleDown: {}, timeScaleDown: {}, startTimeCutOff: {}, proportion: {}",
numNodes, traceFile, cpuScaleDown, memScaleDown,
timeScaleDown, startTimeCutOff, affinityRequirementsProportion);
emulatedCluster.runTraceLocally(numNodes, traceFile, cpuScaleDown, memScaleDown, timeScaleDown,
startTimeCutOff, affinityRequirementsProportion);
startTimeCutOff, affinityRequirementsProportion);
}

public static void main(final String[] args) throws Exception {
runWorkload(args);
System.exit(0); // without this, there are non-daemon threads that prevent JVM shutdown
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void runTrace(final NamespacedKubernetesClient client, final String fileN
final int timeScaleDown, final int startTimeCutOff, final int affinityProportion)
throws Exception {
runTrace(client, fileName, deployer, schedulerName, cpuScaleDown, memScaleDown, timeScaleDown,
startTimeCutOff, 0, 60);
startTimeCutOff, affinityProportion, 60);
}

public void runTrace(final NamespacedKubernetesClient client, final String fileName, final IPodDeployer deployer,
Expand Down Expand Up @@ -148,7 +148,7 @@ public void runTrace(final NamespacedKubernetesClient client, final String fileN
" will happen at {}s. Sleeping for {}s before teardown.", totalPods, maxStart,
maxEnd, maxEnd);

final List<Object> objects = Futures.successfulAsList(deletions).get(maxEnd + 100, TimeUnit.SECONDS);
final List<Object> objects = Futures.successfulAsList(deletions).get(maxEnd + 30, TimeUnit.SECONDS);
assert objects.size() != 0;
}

Expand Down
17 changes: 17 additions & 0 deletions k8s-scheduler/src/test/java/com/vmware/dcm/WorkloadReplayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2018-2020 VMware, Inc. All Rights Reserved.
* SPDX-License-Identifier: BSD-2
*/

package com.vmware.dcm;

import org.junit.jupiter.api.Test;

public class WorkloadReplayTest {

@Test
public void runTest() throws Exception {
final String[] args = {"-n", "500", "-f", "test-data.txt", "-c", "100", "-m", "200", "-t", "100", "-s", "0"};
EmulatedCluster.runWorkload(args);
}
}

0 comments on commit 8e481b8

Please sign in to comment.