Skip to content
Snippets Groups Projects
Commit af355c1a authored by Sören Henning's avatar Sören Henning
Browse files

Add JavaDoc

parent 37162858
No related branches found
No related tags found
2 merge requests!86Zookeeper free workload generator,!84Gitlab CI for Theodolite-Kotlin-Quarkus
Pipeline #1988 skipped
This commit is part of merge request !86. Comments created here will be created in the context of that merge request.
...@@ -5,6 +5,9 @@ import java.util.Objects; ...@@ -5,6 +5,9 @@ import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerConfig;
/**
* A Theodolite load generator.
*/
public final class LoadGenerator { public final class LoadGenerator {
private static final String SENSOR_PREFIX_DEFAULT = "s_"; private static final String SENSOR_PREFIX_DEFAULT = "s_";
...@@ -49,6 +52,9 @@ public final class LoadGenerator { ...@@ -49,6 +52,9 @@ public final class LoadGenerator {
return this; return this;
} }
/**
* Run the constructed load generator until cancellation.
*/
public void run() { public void run() {
Objects.requireNonNull(this.clusterConfig, "No cluster config set."); Objects.requireNonNull(this.clusterConfig, "No cluster config set.");
Objects.requireNonNull(this.generatorConfig, "No generator config set."); Objects.requireNonNull(this.generatorConfig, "No generator config set.");
...@@ -64,6 +70,9 @@ public final class LoadGenerator { ...@@ -64,6 +70,9 @@ public final class LoadGenerator {
runner.runBlocking(); runner.runBlocking();
} }
/**
* Create a basic {@link LoadGenerator} from its default values.
*/
public static LoadGenerator fromDefaults() { public static LoadGenerator fromDefaults() {
return new LoadGenerator() return new LoadGenerator()
.setClusterConfig(new ClusterConfig()) .setClusterConfig(new ClusterConfig())
...@@ -79,6 +88,9 @@ public final class LoadGenerator { ...@@ -79,6 +88,9 @@ public final class LoadGenerator {
.forConstantValue(VALUE_DEFAULT))); .forConstantValue(VALUE_DEFAULT)));
} }
/**
* Create a basic {@link LoadGenerator} from environment variables.
*/
public static LoadGenerator fromEnvironment() { public static LoadGenerator fromEnvironment() {
final String bootstrapServer = Objects.requireNonNullElse( final String bootstrapServer = Objects.requireNonNullElse(
System.getenv(ConfigurationKeys.BOOTSTRAP_SERVER), System.getenv(ConfigurationKeys.BOOTSTRAP_SERVER),
...@@ -137,9 +149,4 @@ public final class LoadGenerator { ...@@ -137,9 +149,4 @@ public final class LoadGenerator {
.forConstantValue(value))); .forConstantValue(value)));
} }
public static void main(final String[] args) {
LoadGenerator.fromEnvironment()
.run();
}
} }
package theodolite.commons.workloadgeneration; package theodolite.commons.workloadgeneration;
import org.slf4j.Logger; /**
import org.slf4j.LoggerFactory; * Configuration of a load generator.
*/
public class LoadGeneratorConfig { public class LoadGeneratorConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(LoadGeneratorConfig.class);
private final MessageGenerator messageGenerator; private final MessageGenerator messageGenerator;
private BeforeAction beforeAction = BeforeAction.doNothing(); private BeforeAction beforeAction = BeforeAction.doNothing();
private int threads = 1; private int threads = 1;
...@@ -17,10 +15,8 @@ public class LoadGeneratorConfig { ...@@ -17,10 +15,8 @@ public class LoadGeneratorConfig {
public LoadGeneratorConfig( public LoadGeneratorConfig(
final MessageGenerator messageGenerator, final MessageGenerator messageGenerator,
final BeforeAction beforeAction,
final int threads) { final int threads) {
this.messageGenerator = messageGenerator; this.messageGenerator = messageGenerator;
this.beforeAction = beforeAction;
this.threads = threads; this.threads = threads;
} }
......
...@@ -7,6 +7,10 @@ import java.util.concurrent.TimeUnit; ...@@ -7,6 +7,10 @@ import java.util.concurrent.TimeUnit;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* A {@link LoadGeneratorExecution} represents the execution of load generator, i.e., it can be
* started and stopped.
*/
public class LoadGeneratorExecution { public class LoadGeneratorExecution {
private static final Logger LOGGER = LoggerFactory.getLogger(LoadGeneratorExecution.class); private static final Logger LOGGER = LoggerFactory.getLogger(LoadGeneratorExecution.class);
...@@ -16,6 +20,10 @@ public class LoadGeneratorExecution { ...@@ -16,6 +20,10 @@ public class LoadGeneratorExecution {
private final MessageGenerator messageGenerator; private final MessageGenerator messageGenerator;
private final ScheduledExecutorService executor; private final ScheduledExecutorService executor;
/**
* Create a new {@link LoadGeneratorExecution} for a given {@link WorkloadDefinition} and a
* {@link MessageGenerator}. Load is generated by the given number of threads.
*/
public LoadGeneratorExecution( public LoadGeneratorExecution(
final WorkloadDefinition workloadDefinition, final WorkloadDefinition workloadDefinition,
final MessageGenerator messageGenerator, final MessageGenerator messageGenerator,
...@@ -25,6 +33,9 @@ public class LoadGeneratorExecution { ...@@ -25,6 +33,9 @@ public class LoadGeneratorExecution {
this.executor = Executors.newScheduledThreadPool(threads); this.executor = Executors.newScheduledThreadPool(threads);
} }
/**
* Start the load generation and run it until it is stopped.
*/
public void start() { public void start() {
LOGGER.info("Beginning of Experiment..."); LOGGER.info("Beginning of Experiment...");
LOGGER.info("Generating records for {} keys.", LOGGER.info("Generating records for {} keys.",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment