Browse Source
* Allow the Trogdor agent to be started in "exec mode", where it simply runs a single task and exits after it is complete. * For AgentClient and CoordinatorClient, allow the user to pass the path to a file containing JSON, instead of specifying the JSON object in the command-line text itself. This means that we can get rid of the bash scripts whose only function was to load task specs into a bash string and run a Trogdor command. * Print dates and times in a human-readable way, rather than as numbers of milliseconds. * When listing tasks or workers, output human-readable tables of information. * Allow the user to filter on task ID name, task ID pattern, or task state. * Support a --json flag to provide raw JSON output if desired. Reviewed-by: David Arthur <mumrah@gmail.com>, Stanislav Kozlovski <stanislav_kozlovski@outlook.com>pull/6196/head
Colin Patrick McCabe
6 years ago
committed by
GitHub
26 changed files with 1204 additions and 407 deletions
@ -1,39 +0,0 @@
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env bash |
||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
||||
# contributor license agreements. See the NOTICE file distributed with |
||||
# this work for additional information regarding copyright ownership. |
||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
# (the "License"); you may not use this file except in compliance with |
||||
# the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
COORDINATOR_ENDPOINT="localhost:8889" |
||||
TASK_ID="consume_bench_$RANDOM" |
||||
TASK_SPEC=$( |
||||
cat <<EOF |
||||
{ |
||||
"id": "$TASK_ID", |
||||
"spec": { |
||||
"class": "org.apache.kafka.trogdor.workload.ConsumeBenchSpec", |
||||
"durationMs": 10000000, |
||||
"consumerNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 1000, |
||||
"threadsPerWorker": 5, |
||||
"consumerGroup": "cg", |
||||
"maxMessages": 10000, |
||||
"activeTopics": ["foo[1-3]"] |
||||
} |
||||
} |
||||
EOF |
||||
) |
||||
|
||||
./bin/trogdor.sh client --create-task "${TASK_SPEC}" "${COORDINATOR_ENDPOINT}" |
||||
echo "\$TASK_ID = $TASK_ID" |
@ -1,47 +0,0 @@
@@ -1,47 +0,0 @@
|
||||
#!/usr/bin/env bash |
||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
||||
# contributor license agreements. See the NOTICE file distributed with |
||||
# this work for additional information regarding copyright ownership. |
||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
# (the "License"); you may not use this file except in compliance with |
||||
# the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
COORDINATOR_ENDPOINT="localhost:8889" |
||||
TASK_ID="produce_bench_$RANDOM" |
||||
TASK_SPEC=$( |
||||
cat <<EOF |
||||
{ |
||||
"id": "$TASK_ID", |
||||
"spec": { |
||||
"class": "org.apache.kafka.trogdor.workload.ProduceBenchSpec", |
||||
"durationMs": 10000000, |
||||
"producerNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 10000, |
||||
"maxMessages": 50000, |
||||
"activeTopics": { |
||||
"foo[1-3]": { |
||||
"numPartitions": 10, |
||||
"replicationFactor": 1 |
||||
} |
||||
}, |
||||
"inactiveTopics": { |
||||
"foo[4-5]": { |
||||
"numPartitions": 10, |
||||
"replicationFactor": 1 |
||||
} |
||||
} |
||||
} |
||||
} |
||||
EOF |
||||
) |
||||
./bin/trogdor.sh client --create-task "${TASK_SPEC}" "${COORDINATOR_ENDPOINT}" |
||||
echo "\$TASK_ID = $TASK_ID" |
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env bash |
||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
||||
# contributor license agreements. See the NOTICE file distributed with |
||||
# this work for additional information regarding copyright ownership. |
||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
# (the "License"); you may not use this file except in compliance with |
||||
# the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
COORDINATOR_ENDPOINT="localhost:8889" |
||||
TASK_ID="round_trip_$RANDOM" |
||||
TASK_SPEC=$( |
||||
cat <<EOF |
||||
{ |
||||
"id": "$TASK_ID", |
||||
"spec": { |
||||
"class": "org.apache.kafka.trogdor.workload.RoundTripWorkloadSpec", |
||||
"durationMs": 10000000, |
||||
"clientNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 1000, |
||||
"maxMessages": 100, |
||||
"activeTopics": { |
||||
"${TASK_ID}_topic[0-1]": { |
||||
"numPartitions": 2, |
||||
"replicationFactor": 1 |
||||
} |
||||
} |
||||
} |
||||
} |
||||
EOF |
||||
) |
||||
|
||||
./bin/trogdor.sh client --create-task "${TASK_SPEC}" "${COORDINATOR_ENDPOINT}" |
||||
echo "\$TASK_ID = $TASK_ID" |
@ -1,51 +0,0 @@
@@ -1,51 +0,0 @@
|
||||
#!/usr/bin/env bash |
||||
# Licensed to the Apache Software Foundation (ASF) under one or more |
||||
# contributor license agreements. See the NOTICE file distributed with |
||||
# this work for additional information regarding copyright ownership. |
||||
# The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
# (the "License"); you may not use this file except in compliance with |
||||
# the License. You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
COORDINATOR_ENDPOINT="localhost:8889" |
||||
TASK_ID="produce_bench_$RANDOM" |
||||
TASK_SPEC=$( |
||||
cat <<EOF |
||||
{ |
||||
"id": "$TASK_ID", |
||||
"spec": { |
||||
"class": "org.apache.kafka.trogdor.workload.ProduceBenchSpec", |
||||
"durationMs": 10000000, |
||||
"producerNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 100, |
||||
"maxMessages": 500, |
||||
"transactionGenerator" : { |
||||
"type" : "uniform", |
||||
"messagesPerTransaction" : 50 |
||||
}, |
||||
"activeTopics": { |
||||
"foo[1-3]": { |
||||
"numPartitions": 3, |
||||
"replicationFactor": 1 |
||||
} |
||||
}, |
||||
"inactiveTopics": { |
||||
"foo[4-5]": { |
||||
"numPartitions": 3, |
||||
"replicationFactor": 1 |
||||
} |
||||
} |
||||
} |
||||
} |
||||
EOF |
||||
) |
||||
./bin/trogdor.sh client --create-task "${TASK_SPEC}" "${COORDINATOR_ENDPOINT}" |
||||
echo "\$TASK_ID = $TASK_ID" |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one or more |
||||
// contributor license agreements. See the NOTICE file distributed with |
||||
// this work for additional information regarding copyright ownership. |
||||
// The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
// (the "License"); you may not use this file except in compliance with |
||||
// the License. You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
|
||||
// |
||||
// An example task specification for running a round trip test in Trogdor. |
||||
// See TROGDOR.md for details. |
||||
// |
||||
|
||||
{ |
||||
"class": "org.apache.kafka.trogdor.workload.RoundTripWorkloadSpec", |
||||
"durationMs": 10000000, |
||||
"clientNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 1000, |
||||
"maxMessages": 100, |
||||
"activeTopics": { |
||||
"round_trip_topic[0-1]": { |
||||
"numPartitions": 2, |
||||
"replicationFactor": 1 |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one or more |
||||
// contributor license agreements. See the NOTICE file distributed with |
||||
// this work for additional information regarding copyright ownership. |
||||
// The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
// (the "License"); you may not use this file except in compliance with |
||||
// the License. You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
|
||||
// |
||||
// An example task specification for running a consumer benchmark in Trogdor. |
||||
// See TROGDOR.md for details. |
||||
// |
||||
|
||||
{ |
||||
"class": "org.apache.kafka.trogdor.workload.ConsumeBenchSpec", |
||||
"durationMs": 10000000, |
||||
"consumerNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 1000, |
||||
"threadsPerWorker": 5, |
||||
"consumerGroup": "cg", |
||||
"maxMessages": 10000, |
||||
"activeTopics": [ "foo[1-3]" ] |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one or more |
||||
// contributor license agreements. See the NOTICE file distributed with |
||||
// this work for additional information regarding copyright ownership. |
||||
// The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
// (the "License"); you may not use this file except in compliance with |
||||
// the License. You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
|
||||
// |
||||
// An example task specification for running a producer benchmark in Trogdor. |
||||
// See TROGDOR.md for details. |
||||
// |
||||
|
||||
{ |
||||
"class": "org.apache.kafka.trogdor.workload.ProduceBenchSpec", |
||||
"durationMs": 10000000, |
||||
"producerNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 10000, |
||||
"maxMessages": 50000, |
||||
"activeTopics": { |
||||
"foo[1-3]": { |
||||
"numPartitions": 10, |
||||
"replicationFactor": 1 |
||||
} |
||||
}, |
||||
"inactiveTopics": { |
||||
"foo[4-5]": { |
||||
"numPartitions": 10, |
||||
"replicationFactor": 1 |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one or more |
||||
// contributor license agreements. See the NOTICE file distributed with |
||||
// this work for additional information regarding copyright ownership. |
||||
// The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
// (the "License"); you may not use this file except in compliance with |
||||
// the License. You may obtain a copy of the License at |
||||
// |
||||
// http://www.apache.org/licenses/LICENSE-2.0 |
||||
// |
||||
// Unless required by applicable law or agreed to in writing, software |
||||
// distributed under the License is distributed on an "AS IS" BASIS, |
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
// See the License for the specific language governing permissions and |
||||
// limitations under the License. |
||||
|
||||
// |
||||
// An example task specification for running a transactional producer benchmark |
||||
in Trogdor. See TROGDOR.md for details. |
||||
// |
||||
|
||||
{ |
||||
"class": "org.apache.kafka.trogdor.workload.ProduceBenchSpec", |
||||
"durationMs": 10000000, |
||||
"producerNode": "node0", |
||||
"bootstrapServers": "localhost:9092", |
||||
"targetMessagesPerSec": 100, |
||||
"maxMessages": 500, |
||||
"transactionGenerator" : { |
||||
"type" : "uniform", |
||||
"messagesPerTransaction" : 50 |
||||
}, |
||||
"activeTopics": { |
||||
"foo[1-3]": { |
||||
"numPartitions": 3, |
||||
"replicationFactor": 1 |
||||
} |
||||
}, |
||||
"inactiveTopics": { |
||||
"foo[4-5]": { |
||||
"numPartitions": 3, |
||||
"replicationFactor": 1 |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,114 @@
@@ -0,0 +1,114 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.kafka.trogdor.common; |
||||
|
||||
import java.time.Duration; |
||||
import java.time.ZoneOffset; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Utilities for formatting strings. |
||||
*/ |
||||
public class StringFormatter { |
||||
/** |
||||
* Pretty-print a date string. |
||||
* |
||||
* @param timeMs The time since the epoch in milliseconds. |
||||
* @param zoneOffset The time zone offset. |
||||
* @return The date string in ISO format. |
||||
*/ |
||||
public static String dateString(long timeMs, ZoneOffset zoneOffset) { |
||||
return new Date(timeMs).toInstant(). |
||||
atOffset(zoneOffset). |
||||
format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); |
||||
} |
||||
|
||||
/** |
||||
* Pretty-print a duration. |
||||
* |
||||
* @param periodMs The duration in milliseconds. |
||||
* @return A human-readable duration string. |
||||
*/ |
||||
public static String durationString(long periodMs) { |
||||
StringBuilder bld = new StringBuilder(); |
||||
Duration duration = Duration.ofMillis(periodMs); |
||||
long hours = duration.toHours(); |
||||
if (hours > 0) { |
||||
bld.append(hours).append("h"); |
||||
duration = duration.minusHours(hours); |
||||
} |
||||
long minutes = duration.toMinutes(); |
||||
if (minutes > 0) { |
||||
bld.append(minutes).append("m"); |
||||
duration = duration.minusMinutes(minutes); |
||||
} |
||||
long seconds = duration.getSeconds(); |
||||
if ((seconds != 0) || bld.toString().isEmpty()) { |
||||
bld.append(seconds).append("s"); |
||||
} |
||||
return bld.toString(); |
||||
} |
||||
|
||||
/** |
||||
* Formats strings in a grid pattern. |
||||
* |
||||
* All entries in the same column will have the same width. |
||||
* |
||||
* @param lines A list of lines. Each line contains a list of columns. |
||||
* Each line must contain the same number of columns. |
||||
* @return The string. |
||||
*/ |
||||
public static String prettyPrintGrid(List<List<String>> lines) { |
||||
int numColumns = -1; |
||||
int rowIndex = 0; |
||||
for (List<String> col : lines) { |
||||
if (numColumns == -1) { |
||||
numColumns = col.size(); |
||||
} else if (numColumns != col.size()) { |
||||
throw new RuntimeException("Expected " + numColumns + " columns in row " + |
||||
rowIndex + ", but got " + col.size()); |
||||
} |
||||
rowIndex++; |
||||
} |
||||
List<Integer> widths = new ArrayList<>(numColumns); |
||||
for (int x = 0; x < numColumns; x++) { |
||||
int w = 0; |
||||
for (List<String> cols : lines) { |
||||
w = Math.max(w, cols.get(x).length() + 1); |
||||
} |
||||
widths.add(w); |
||||
} |
||||
StringBuilder bld = new StringBuilder(); |
||||
for (int y = 0; y < lines.size(); y++) { |
||||
List<String> cols = lines.get(y); |
||||
for (int x = 0; x < cols.size(); x++) { |
||||
String val = cols.get(x); |
||||
int minWidth = widths.get(x); |
||||
bld.append(val); |
||||
for (int i = 0; i < minWidth - val.length(); i++) { |
||||
bld.append(" "); |
||||
} |
||||
} |
||||
bld.append(String.format("%n")); |
||||
} |
||||
return bld.toString(); |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.kafka.trogdor.common; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
import org.apache.kafka.test.TestUtils; |
||||
import org.junit.Rule; |
||||
import org.junit.Test; |
||||
import org.junit.rules.Timeout; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.io.File; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.nio.file.Files; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertFalse; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
public class JsonUtilTest { |
||||
private static final Logger log = LoggerFactory.getLogger(JsonUtilTest.class); |
||||
|
||||
@Rule |
||||
final public Timeout globalTimeout = Timeout.millis(120000); |
||||
|
||||
@Test |
||||
public void testOpenBraceComesFirst() { |
||||
assertTrue(JsonUtil.openBraceComesFirst("{}")); |
||||
assertTrue(JsonUtil.openBraceComesFirst(" \t{\"foo\":\"bar\"}")); |
||||
assertTrue(JsonUtil.openBraceComesFirst(" { \"foo\": \"bar\" }")); |
||||
assertFalse(JsonUtil.openBraceComesFirst("/my/file/path")); |
||||
assertFalse(JsonUtil.openBraceComesFirst("mypath")); |
||||
assertFalse(JsonUtil.openBraceComesFirst(" blah{}")); |
||||
} |
||||
|
||||
static final class Foo { |
||||
@JsonProperty |
||||
final int bar; |
||||
|
||||
@JsonCreator |
||||
Foo(@JsonProperty("bar") int bar) { |
||||
this.bar = bar; |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testObjectFromCommandLineArgument() throws Exception { |
||||
assertEquals(123, JsonUtil.<Foo> |
||||
objectFromCommandLineArgument("{\"bar\":123}", Foo.class).bar); |
||||
assertEquals(1, JsonUtil.<Foo> |
||||
objectFromCommandLineArgument(" {\"bar\": 1} ", Foo.class).bar); |
||||
File tempFile = TestUtils.tempFile(); |
||||
try { |
||||
Files.write(tempFile.toPath(), |
||||
"{\"bar\": 456}".getBytes(StandardCharsets.UTF_8)); |
||||
assertEquals(456, JsonUtil.<Foo> |
||||
objectFromCommandLineArgument(tempFile.getAbsolutePath(), Foo.class).bar); |
||||
} finally { |
||||
Files.delete(tempFile.toPath()); |
||||
} |
||||
} |
||||
}; |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.kafka.trogdor.common; |
||||
|
||||
import org.junit.Rule; |
||||
import org.junit.rules.Timeout; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.junit.Test; |
||||
|
||||
import java.time.ZoneOffset; |
||||
import java.util.Arrays; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
import static org.apache.kafka.trogdor.common.StringFormatter.durationString; |
||||
import static org.apache.kafka.trogdor.common.StringFormatter.dateString; |
||||
|
||||
public class StringFormatterTest { |
||||
private static final Logger log = LoggerFactory.getLogger(StringFormatterTest.class); |
||||
|
||||
@Rule |
||||
final public Timeout globalTimeout = Timeout.millis(120000); |
||||
|
||||
@Test |
||||
public void testDateString() { |
||||
assertEquals("2019-01-08T20:59:29.85Z", |
||||
dateString(1546981169850L, ZoneOffset.UTC)); |
||||
} |
||||
|
||||
@Test |
||||
public void testDurationString() { |
||||
assertEquals("1m", durationString(60000)); |
||||
assertEquals("1m1s", durationString(61000)); |
||||
assertEquals("1m1s", durationString(61200)); |
||||
assertEquals("5s", durationString(5000)); |
||||
assertEquals("2h", durationString(7200000)); |
||||
assertEquals("2h1s", durationString(7201000)); |
||||
assertEquals("2h5m3s", durationString(7503000)); |
||||
} |
||||
|
||||
@Test |
||||
public void testPrettyPrintGrid() { |
||||
assertEquals(String.format( |
||||
"ANIMAL NUMBER INDEX %n" + |
||||
"lion 1 12345 %n" + |
||||
"manatee 50 1 %n"), |
||||
StringFormatter.prettyPrintGrid( |
||||
Arrays.asList(Arrays.asList("ANIMAL", "NUMBER", "INDEX"), |
||||
Arrays.asList("lion", "1", "12345"), |
||||
Arrays.asList("manatee", "50", "1")))); |
||||
} |
||||
}; |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.apache.kafka.trogdor.coordinator; |
||||
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
||||
import org.apache.kafka.trogdor.rest.TaskDone; |
||||
import org.apache.kafka.trogdor.rest.TaskPending; |
||||
import org.apache.kafka.trogdor.rest.TaskRunning; |
||||
import org.apache.kafka.trogdor.rest.TaskStopping; |
||||
import org.apache.kafka.trogdor.task.NoOpTaskSpec; |
||||
import org.junit.Rule; |
||||
import org.junit.rules.Timeout; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.junit.Test; |
||||
|
||||
import java.time.ZoneOffset; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
public class CoordinatorClientTest { |
||||
private static final Logger log = LoggerFactory.getLogger(CoordinatorTest.class); |
||||
|
||||
@Rule |
||||
final public Timeout globalTimeout = Timeout.millis(120000); |
||||
|
||||
@Test |
||||
public void testPrettyPrintTaskInfo() { |
||||
assertEquals("Will start at 2019-01-08T07:05:59.85Z", |
||||
CoordinatorClient.prettyPrintTaskInfo( |
||||
new TaskPending(new NoOpTaskSpec(1546931159850L, 9000)), |
||||
ZoneOffset.UTC)); |
||||
assertEquals("Started 2009-07-07T01:45:59.85Z; will stop after 9s", |
||||
CoordinatorClient.prettyPrintTaskInfo( |
||||
new TaskRunning(new NoOpTaskSpec(1146931159850L, 9000), |
||||
1246931159850L, |
||||
JsonNodeFactory.instance.objectNode()), ZoneOffset.UTC)); |
||||
assertEquals("Started 2009-07-07T01:45:59.85Z", |
||||
CoordinatorClient.prettyPrintTaskInfo( |
||||
new TaskStopping(new NoOpTaskSpec(1146931159850L, 9000), |
||||
1246931159850L, |
||||
JsonNodeFactory.instance.objectNode()), ZoneOffset.UTC)); |
||||
assertEquals("FINISHED at 2019-01-08T20:59:29.85Z after 10s", |
||||
CoordinatorClient.prettyPrintTaskInfo( |
||||
new TaskDone(new NoOpTaskSpec(0, 1000), |
||||
1546981159850L, |
||||
1546981169850L, |
||||
"", |
||||
false, |
||||
JsonNodeFactory.instance.objectNode()), ZoneOffset.UTC)); |
||||
assertEquals("CANCELLED at 2019-01-08T20:59:29.85Z after 10s", |
||||
CoordinatorClient.prettyPrintTaskInfo( |
||||
new TaskDone(new NoOpTaskSpec(0, 1000), |
||||
1546981159850L, |
||||
1546981169850L, |
||||
"", |
||||
true, |
||||
JsonNodeFactory.instance.objectNode()), ZoneOffset.UTC)); |
||||
assertEquals("FAILED at 2019-01-08T20:59:29.85Z after 10s", |
||||
CoordinatorClient.prettyPrintTaskInfo( |
||||
new TaskDone(new NoOpTaskSpec(0, 1000), |
||||
1546981159850L, |
||||
1546981169850L, |
||||
"foobar", |
||||
true, |
||||
JsonNodeFactory.instance.objectNode()), ZoneOffset.UTC)); |
||||
} |
||||
}; |
Loading…
Reference in new issue