12
12
import java .util .HashMap ;
13
13
import java .util .Map ;
14
14
import java .util .concurrent .TimeUnit ;
15
+ import java .util .function .Predicate ;
16
+ import java .util .regex .Pattern ;
15
17
16
18
public class BenchmarksSettings {
17
19
@@ -25,6 +27,8 @@ public class BenchmarksSettings {
25
27
private static final Duration RAMP_UP_DURATION = Duration .ofSeconds (10 );
26
28
private static final Duration RAMP_UP_INTERVAL = Duration .ofSeconds (1 );
27
29
private static final boolean CONSOLE_REPORTER_ENABLED = true ;
30
+ private static final String ALIAS_PATTERN = "^[.a-zA-Z_0-9]+$" ;
31
+ private static final Predicate <String > ALIAS_PREDICATE = Pattern .compile (ALIAS_PATTERN ).asPredicate ();
28
32
29
33
private final int nThreads ;
30
34
private final Duration executionTaskDuration ;
@@ -68,7 +72,13 @@ private BenchmarksSettings(Builder builder) {
68
72
69
73
String time = LocalDateTime .ofInstant (Instant .now (), ZoneOffset .UTC )
70
74
.format (DateTimeFormatter .ofPattern ("yyyy-MM-dd-HH-mm-ss" ));
71
- this .csvReporterDirectory = Paths .get ("reports" , "benchmarks" , find ("alias" , taskName ), time ).toFile ();
75
+
76
+ String alias = find ("alias" , taskName );
77
+ if (!ALIAS_PREDICATE .test (alias )) {
78
+ throw new IllegalArgumentException ("alias '" + alias + "' must match pattern " + ALIAS_PATTERN );
79
+ }
80
+
81
+ this .csvReporterDirectory = Paths .get ("reports" , "benchmarks" , alias , time ).toFile ();
72
82
// noinspection ResultOfMethodCallIgnored
73
83
this .csvReporterDirectory .mkdirs ();
74
84
}
0 commit comments