Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -14,25 +12,26 @@
public class EtwTestController {
private static final DiagnosticsLoggerProxy DIAGNOSTICS_LOGGER = new DiagnosticsLoggerProxy();

private static final String LEVEL = "info";
private static final boolean HAS_EXCEPTION = false;

private final AtomicInteger errorCount = new AtomicInteger();
private final AtomicInteger warnCount = new AtomicInteger();
private final AtomicInteger infoCount = new AtomicInteger();

@GetMapping("/{level}")
public ResponseEntity<String> logPage(
@PathVariable String level,
@RequestParam(name = "e", required = false, defaultValue = "false") boolean hasException) {
String msg = "Hit /" + level + " ";
@GetMapping("/log")
public ResponseEntity<String> logPage() {
String msg = "Hit /" + LEVEL + " ";
int n;
Throwable t = null;
switch (level.toLowerCase()) {
switch (LEVEL.toLowerCase()) {
case "info":
n = infoCount.incrementAndGet();
DIAGNOSTICS_LOGGER.info(msg + n);
break;
case "error":
n = errorCount.incrementAndGet();
if (hasException) {
if (HAS_EXCEPTION) {
t = new Exception("the error " + n);
DIAGNOSTICS_LOGGER.error(msg + n, t);
} else {
Expand All @@ -41,7 +40,7 @@ public ResponseEntity<String> logPage(
break;
case "warn":
n = warnCount.incrementAndGet();
if (hasException) {
if (HAS_EXCEPTION) {
t = new Exception("the warn " + n);
DIAGNOSTICS_LOGGER.warn(msg + n, t);
} else {
Expand All @@ -52,6 +51,6 @@ public ResponseEntity<String> logPage(
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(
level.toUpperCase() + " " + n + (t == null ? "" : "<br/>\n" + t.toString()));
LEVEL.toUpperCase() + " " + n + (t == null ? "" : "<br/>\n" + t.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,29 +232,12 @@ private double rand() {
}

@GetMapping("/start")
public ResponseEntity<String> startTest(
@RequestParam(name = "T", required = false, defaultValue = "1s") String periodStr) {
public ResponseEntity<String> startTest() {
if (future.get() != null) {
return ResponseEntity.status(HttpStatus.CONFLICT).body("Test already in progress.");
}

final Duration period;
try {
if (periodStr.toLowerCase().endsWith("ms")) {
period = Duration.ofMillis(Long.parseLong(periodStr.substring(0, periodStr.length() - 2)));
} else {
period = Duration.parse("PT" + periodStr);
}
} catch (NumberFormatException | DateTimeParseException e) {
return ResponseEntity.badRequest()
.body(
"<p>Period parameter 'T' could not parse \""
+ periodStr
+ "\"</p>"
+ "<p><pre>"
+ ExceptionUtils.getStackTrace(e)
+ "</p>");
}
final Duration period = Duration.parse("PT1s");

final long startTime;
final ScheduledFuture<?> scheduledTask;
Expand Down