Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lehmann_Fabian <[email protected]>
  • Loading branch information
Lehmann-Fabian committed Mar 12, 2024
1 parent 4c89408 commit 5a454d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
46 changes: 24 additions & 22 deletions src/test/java/cws/k8s/scheduler/prediction/MemoryScalerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

public class MemoryScalerTest {

long MB = 1024 * 1024;

private SchedulerConfig getSchedulerConfig( long minMemory, long maxMemory, String memoryPredictor ) {
ObjectMapper objectMapper = new ObjectMapper();
SchedulerConfig schedulerConfig = null;
Expand Down Expand Up @@ -51,82 +53,82 @@ public void initialTest() {
@Test
public void predictAfterSingleTask() {

final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 1024, 2048, "linear" ) );
final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 1024 * MB, 2048 * MB, "linear" ) );
final TestTask task = new TestTask( 1, 1 );
task.setTaskMetrics( getTaskMetric( 1, 1 ) );
task.setTaskMetrics( getTaskMetric( 1, MB ) );
memoryScaler.afterTaskFinished( task );
final TestTask task2 = new TestTask( 2, 2 );
assertEquals( 2, task2.getNewMemoryRequest() );
assertEquals( 2 * MB, task2.getNewMemoryRequest() );
memoryScaler.scaleTask( task2 );
assertEquals( 2, task2.getNewMemoryRequest() );
assertEquals( 2 * MB, task2.getNewMemoryRequest() );

}

@Test
public void predictAfterTwoTasks() {

final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 0, 2048, "linear" ) );
final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 0, 2048*MB, "linear" ) );
final TestTask task = new TestTask( 4, 1 );
task.setTaskMetrics( getTaskMetric( 1, 1 ) );
task.setTaskMetrics( getTaskMetric( 1, 1 * MB ) );
memoryScaler.afterTaskFinished( task );

final TestTask task2 = new TestTask( 4, 2 );
task2.setTaskMetrics( getTaskMetric( 2, 2 ) );
task2.setTaskMetrics( getTaskMetric( 2, 2 * MB ) );
memoryScaler.afterTaskFinished( task2 );

final TestTask taskToPredict = new TestTask( 4, 3 );
assertEquals( 4, taskToPredict.getNewMemoryRequest() );
assertEquals( 4 * MB, taskToPredict.getNewMemoryRequest() );
memoryScaler.scaleTask( taskToPredict );
assertEquals( 3, taskToPredict.getNewMemoryRequest() );
assertEquals( 3 * MB, taskToPredict.getNewMemoryRequest() );

}

@Test
public void considerMin() {

final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 1024, 2048, "linear" ) );
final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 1024 * MB, 2048 * MB, "linear" ) );
final TestTask task = new TestTask( 4, 1 );
task.setTaskMetrics( getTaskMetric( 1, 1 ) );
task.setTaskMetrics( getTaskMetric( 1, MB ) );
memoryScaler.afterTaskFinished( task );

final TestTask task2 = new TestTask( 4, 2 );
task2.setTaskMetrics( getTaskMetric( 2, 2 ) );
task2.setTaskMetrics( getTaskMetric( 2, 2 * MB ) );
memoryScaler.afterTaskFinished( task2 );

final TestTask taskToPredict = new TestTask( 4, 3 );
assertEquals( 4, taskToPredict.getNewMemoryRequest() );
assertEquals( 4 * MB, taskToPredict.getNewMemoryRequest() );
memoryScaler.scaleTask( taskToPredict );
assertEquals( 1024, taskToPredict.getNewMemoryRequest() );
assertEquals( 1024 * MB, taskToPredict.getNewMemoryRequest() );

}

@Test
public void considerMax() {

final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 0, 2, "linear" ) );
final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 0, 2 * MB, "linear" ) );
final TestTask task = new TestTask( 4, 1 );
task.setTaskMetrics( getTaskMetric( 1, 1 ) );
task.setTaskMetrics( getTaskMetric( 1, MB ) );
memoryScaler.afterTaskFinished( task );

final TestTask task2 = new TestTask( 4, 2 );
task2.setTaskMetrics( getTaskMetric( 2, 2 ) );
task2.setTaskMetrics( getTaskMetric( 2, 2 * MB ) );
memoryScaler.afterTaskFinished( task2 );

final TestTask taskToPredict = new TestTask( 4, 3 );
assertEquals( 4, taskToPredict.getNewMemoryRequest() );
assertEquals( 4 * MB, taskToPredict.getNewMemoryRequest() );
memoryScaler.scaleTask( taskToPredict );
assertEquals( 2, taskToPredict.getNewMemoryRequest() );
assertEquals( 2 * MB, taskToPredict.getNewMemoryRequest() );

}

@Test
public void predictWithoutTask() {

final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 1024, 2048, "linear" ) );
final MemoryScaler memoryScaler = new MemoryScaler( getSchedulerConfig( 1024 * MB, 2048 * MB, "linear" ) );
final TestTask task2 = new TestTask( 2, 2 );
assertEquals( 2, task2.getNewMemoryRequest() );
assertEquals( 2 * MB, task2.getNewMemoryRequest() );
memoryScaler.scaleTask( task2 );
assertEquals( 2, task2.getNewMemoryRequest() );
assertEquals( 2 * MB, task2.getNewMemoryRequest() );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public TestTask( double x, double y) {
this.y = y;
}

public TestTask( long memoryRequest, long inputsize ) {
public TestTask( long memoryRequestInMb, long inputsize ) {
this( 0d, 0d );
this.memoryRequest = BigDecimal.valueOf( memoryRequest );
planedMemory = memoryRequest;
this.memoryRequest = BigDecimal.valueOf( memoryRequestInMb * 1048576 );
planedMemory = memoryRequestInMb * 1048576;
this.inputSize = inputsize;
}

Expand Down

0 comments on commit 5a454d9

Please sign in to comment.