Skip to content

Commit

Permalink
Merge pull request #910 from Daimler/feature-908-upgrade-spring
Browse files Browse the repository at this point in the history
Upgrade SpringBoot to 2.5.7
  • Loading branch information
Jeeppler committed Dec 14, 2021
2 parents 224edbd + 905c292 commit 835cf51
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins {
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'org.asciidoctor.jvm.pdf' version '3.3.2'
id 'org.openapi.generator' version '5.2.0'
id 'org.springframework.boot' version '2.5.2' apply false
id 'org.springframework.boot' version '2.5.7' apply false
}
/* check buildsystem */
def githubActor = System.getenv('GITHUB_ACTOR')
Expand Down
14 changes: 9 additions & 5 deletions libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@ ext {

/* autark JUnit parts, with same versions like current used spring boot version */
// https://mvnrepository.com/artifact/junit/junit
junit: "junit:junit:4.13.1",
junit5_impl: 'org.junit.jupiter:junit-jupiter-api:5.6.0',
junit5_runtime: 'org.junit.jupiter:junit-jupiter-engine:5.6.0',
junit: "junit:junit:4.13.2",
junit5_impl: 'org.junit.jupiter:junit-jupiter-api:5.7.2',
junit5_runtime: 'org.junit.jupiter:junit-jupiter-engine:5.7.2',

// Adopting existing Junit4 to Junit5 tests:
// currently we keep our exting Junit4 tests and do NOT transform them.
// If we start this, please refer:
// https://github.com/junit-team/junit5-samples/tree/master/junit5-migration-gradle

// https://mvnrepository.com/artifact/org.mockito/mockito-core
mockito: "org.mockito:mockito-core:3.6.0", //IMPORTANT: keep this at same level as used in Spring BOOT version
mockito: "org.mockito:mockito-core:3.9.0", //IMPORTANT: keep this at same level as used in Spring BOOT version

// https://mvnrepository.com/artifact/org.mockito/mockito-inline
mockito_inline: "org.mockito:mockito-inline:3.9.0",


// https://mvnrepository.com/artifact/org.hamcrest/hamcrest-library
hamcrest: "org.hamcrest:hamcrest-library:2.2", //IMPORTANT: keep this at same level as used in Spring BOOT version

// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
slf4j: "org.slf4j:slf4j-api:1.7.30", //IMPORTANT: keep this at same level as used in Spring BOOT version
slf4j: "org.slf4j:slf4j-api:1.7.32", //IMPORTANT: keep this at same level as used in Spring BOOT version

/* spring */
springboot_starter_thymeleaf: "org.springframework.boot:spring-boot-starter-thymeleaf",
Expand Down
1 change: 1 addition & 0 deletions sechub-analyzer-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {

testCompile library.junit
testCompile library.mockito
testCompile library.mockito_inline
testCompile library.hamcrest
}

Expand Down
1 change: 1 addition & 0 deletions sechub-client-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
testRuntimeOnly library.junit5_runtime

testImplementation library.mockito
testImplementation library.mockito_inline
testImplementation library.hamcrest
}

Expand Down
1 change: 1 addition & 0 deletions sechub-commons-model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ dependencies{
testRuntimeOnly library.junit5_runtime

testImplementation library.mockito
testImplementation library.mockito_inline
testImplementation library.hamcrest
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
package com.daimler.sechub.sharedkernel.monitoring;

/**
* Memory runtime data
*
* @author Albert Tregnaghi
*
*/
public class MemoryRuntime {

public long getMaxMemory() {
return Runtime.getRuntime().maxMemory();
}

public long getTotalMemory() {
return Runtime.getRuntime().totalMemory();
}

public long getFreeMemory() {
return Runtime.getRuntime().freeMemory();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,59 @@
import com.daimler.sechub.sharedkernel.util.SimpleByteUtil;

public class MemoryUsageMonitor {


private static final Logger LOG = LoggerFactory.getLogger(MemoryUsageMonitor.class);

private static final String KEY_DESCRIPTION = "description";

private Runtime runtime;
private MemoryRuntime memoryRuntime;
private CacheableMonitoringValue memoryData;
private Object monitor = new Object();
MemoryUsageMonitor(Runtime runtime, long cacheTimeInMillis) {
this.runtime=runtime;

MemoryUsageMonitor(MemoryRuntime runtime, long cacheTimeInMillis) {
this.memoryRuntime = runtime;
setCacheTimeInMillis(cacheTimeInMillis);
}

/**
* Resolves percentage of memory usage (results can be from 0 to 100)
*
* @return percentage of memory usage
*/
public double getMemoryUsageInPercent() {
if (runtime == null) {
if (memoryRuntime == null) {
return -1;
}
synchronized (monitor) {
if (memoryData.isCacheValid()) {
return memoryData.getValue();
}
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();

long maxMemory = memoryRuntime.getMaxMemory();
long allocatedMemory = memoryRuntime.getTotalMemory();
long freeMemory = memoryRuntime.getFreeMemory();

long memoryMaxOnePercent = maxMemory / 100;
long usedMemory = allocatedMemory-freeMemory;


long usedMemory = allocatedMemory - freeMemory;

String maxMemoryString = SimpleByteUtil.createHumanReadableBytesLengthDescription(maxMemory);
String allocatedMemoryString = SimpleByteUtil.createHumanReadableBytesLengthDescription(allocatedMemory);
String freeMemoryString = SimpleByteUtil.createHumanReadableBytesLengthDescription(freeMemory);

if (LOG.isTraceEnabled()) {
LOG.trace("Checked memory data, maxMemory:{}, allocatedMemory:{}, freeMemory:{}", maxMemoryString, allocatedMemoryString, freeMemoryString);
}
double memoryUsageInPercent=usedMemory / memoryMaxOnePercent;

double memoryUsageInPercent = usedMemory / memoryMaxOnePercent;

if (memoryUsageInPercent < 0) {
memoryData.setValue(memoryUsageInPercent);
} else {
memoryData.setValue(memoryUsageInPercent);
}
double result = memoryData.getValue();
LOG.trace("Checked memory usage, value now:{}", result);

StringBuilder sb = new StringBuilder();
sb.append("memory usage:").append(result).append("%");
sb.append(", max:");
Expand All @@ -69,9 +68,9 @@ public double getMemoryUsageInPercent() {
sb.append(allocatedMemoryString);
sb.append(", free:");
sb.append(freeMemoryString);

memoryData.setAdditionalData(KEY_DESCRIPTION, sb.toString());

return result;
}

Expand All @@ -80,15 +79,15 @@ public double getMemoryUsageInPercent() {
public String getDescription() {
synchronized (monitor) {
String description = (String) memoryData.getAdditionalData(KEY_DESCRIPTION);
if (description==null) {
if (description == null) {
return "<no memory data available>";
}
return description;
}
}

public void setCacheTimeInMillis(long cacheTimeInMilliseconds) {
this.memoryData=new CacheableMonitoringValue(cacheTimeInMilliseconds);
this.memoryData = new CacheableMonitoringValue(cacheTimeInMilliseconds);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SystemMonitorService() {
} catch (IOException e) {
LOG.error("Will not be able to check OS!", e);
}
memoryUsageMonitor = new MemoryUsageMonitor(Runtime.getRuntime(), cacheTimeInMilliseconds);
memoryUsageMonitor = new MemoryUsageMonitor(new MemoryRuntime(), cacheTimeInMilliseconds);
cpuMonitor = new CPUMonitor(osMBean, cacheTimeInMilliseconds);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
package com.daimler.sechub.sharedkernel.monitoring;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class MemoryRuntimeTest {

@Test
void getter_for_memory_have_same_values_than_system_runtime_pendants() {
/* prepare */
MemoryRuntime runtimeToTest = new MemoryRuntime();
Runtime systemRuntime = Runtime.getRuntime();

// define/consume local variables before calling system runtime
long maxMemory = 0;
long totalMemory = 1;
long freeMemory = 2;

long maxMemory2 = 3;
long totalMemory2 = 4;
long freeMemory2 = 5;

/* execute */
maxMemory = systemRuntime.maxMemory();
totalMemory = systemRuntime.totalMemory();
freeMemory = systemRuntime.freeMemory();

maxMemory2 = runtimeToTest.getMaxMemory();
totalMemory2 = runtimeToTest.getTotalMemory();
freeMemory2 = runtimeToTest.getFreeMemory();

/* test */
assertEquals(maxMemory, maxMemory2);
assertEquals(totalMemory, totalMemory2);
assertEquals(freeMemory, freeMemory2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,57 @@
public class MemoryUsagePercentMonitorTest {

private MemoryUsageMonitor monitorToTest;
private Runtime runtime;
private MemoryRuntime memoryRuntime;

@Before
public void before() throws Exception {
runtime = mock(Runtime.class);
monitorToTest = new MemoryUsageMonitor(runtime, 200);
memoryRuntime = mock(MemoryRuntime.class);
monitorToTest = new MemoryUsageMonitor(memoryRuntime, 200);
}

@Test
public void max_memory_allocated_half_time_nothing_free__results_in_50_percent() {
/* prepare maximum allocated, but 500 are free */
when(runtime.maxMemory()).thenReturn(1000L);
when(runtime.totalMemory()).thenReturn(500L); // allocated
when(runtime.freeMemory()).thenReturn(0L);
when(memoryRuntime.getMaxMemory()).thenReturn(1000L);
when(memoryRuntime.getTotalMemory()).thenReturn(500L); // allocated
when(memoryRuntime.getFreeMemory()).thenReturn(0L);

/* execute */
double result = monitorToTest.getMemoryUsageInPercent();

/* test */
assertEquals("Expected 50%",50,result,0.01);
assertEquals("Expected 50%", 50, result, 0.01);

}




@Test
public void max_memory_allocated__but_half_is_still_free__results_in_50_percent() {
/* prepare maximum allocated, but 500 are free */
when(runtime.maxMemory()).thenReturn(1000L);
when(runtime.totalMemory()).thenReturn(1000L); // allocated
when(runtime.freeMemory()).thenReturn(500L);
when(memoryRuntime.getMaxMemory()).thenReturn(1000L);
when(memoryRuntime.getTotalMemory()).thenReturn(1000L); // allocated
when(memoryRuntime.getFreeMemory()).thenReturn(500L);

/* execute */
double result = monitorToTest.getMemoryUsageInPercent();

/* test */
assertEquals("Expected 50%",50.0,result,0.01);
assertEquals("Expected 50%", 50.0, result, 0.01);

}

@Test
public void max_memory_allocated_half_time_but_all_allocated_is_also_free__results_in_0_percent() {
/* prepare maximum allocated, but 500 are free */
when(runtime.maxMemory()).thenReturn(1000L);
when(runtime.totalMemory()).thenReturn(500L); // allocated
when(runtime.freeMemory()).thenReturn(500L);
when(memoryRuntime.getMaxMemory()).thenReturn(1000L);
when(memoryRuntime.getTotalMemory()).thenReturn(500L); // allocated
when(memoryRuntime.getFreeMemory()).thenReturn(500L);

/* execute */
double result = monitorToTest.getMemoryUsageInPercent();

/* test */
assertEquals("Expected 0%",0,result,0.01);
assertEquals("Expected 0%", 0, result, 0.01);

}

}
1 change: 1 addition & 0 deletions sechub-storage-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {

testCompile library.junit
testCompile library.mockito
testCompile library.mockito_inline
testCompile project(':sechub-testframework')

}
1 change: 1 addition & 0 deletions sechub-storage-s3-aws-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {

testCompile library.junit
testCompile library.mockito
testCompile library.mockito_inline
testCompile project(':sechub-testframework')

}
1 change: 1 addition & 0 deletions sechub-testframework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {

compile library.junit
compile library.mockito
compile library.mockito_inline
compile library.hamcrest
compile library.slf4j

Expand Down

0 comments on commit 835cf51

Please sign in to comment.