Skip to content

Commit

Permalink
feat: Adding topology model classes and junit annotation processing (#…
Browse files Browse the repository at this point in the history
…383)

Signed-off-by: Deepak Mishra <deepak@swirldslabs.com>
  • Loading branch information
deepak-swirlds authored Oct 24, 2023
1 parent b69dd99 commit 9c6930e
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

package com.hedera.fullstack.junit.support.extensions;

import com.hedera.fullstack.junit.support.annotations.application.ApplicationNodes;
import com.hedera.fullstack.junit.support.annotations.application.PlatformApplication;
import com.hedera.fullstack.junit.support.annotations.application.PlatformConfiguration;
import com.hedera.fullstack.junit.support.model.ConfigurationValue;
import com.hedera.fullstack.junit.support.model.NetworkDeploymentConfiguration;
import com.hedera.fullstack.junit.support.model.ResourceShape;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

Expand All @@ -28,7 +38,57 @@ public class TestSetupExtension implements BeforeEachCallback {
*
* @param context the current extension context; never {@code null}
* @throws Exception if an error occurs during callback execution.
*
* <p><img alt="annotation processing call flow" src="annotation-processing.drawio.png"/></p>
*/
@Override
public void beforeEach(final ExtensionContext context) throws Exception {}
public void beforeEach(final ExtensionContext context) throws Exception {

Optional<Method> testMethod = context.getTestMethod();

if (testMethod.isPresent()) {
// FUTURE: add support for NamedApplicationNodes
ApplicationNodes applicationNodes = testMethod.get().getAnnotation(ApplicationNodes.class);
PlatformApplication platformApplication = testMethod.get().getAnnotation(PlatformApplication.class);
PlatformConfiguration platformConfigurations = testMethod.get().getAnnotation(PlatformConfiguration.class);

// Convert the annotations to model class objects
com.hedera.fullstack.junit.support.model.ApplicationNodes.Builder appNodesBuilder =
new com.hedera.fullstack.junit.support.model.ApplicationNodes.Builder();
if (applicationNodes != null) {
appNodesBuilder
.value(applicationNodes.value())
.shape(new ResourceShape.Builder()
.cpuInMillis(applicationNodes.shape().cpuInMillis())
.build());
}

com.hedera.fullstack.junit.support.model.PlatformApplication.Builder platformAppBuilder =
new com.hedera.fullstack.junit.support.model.PlatformApplication.Builder();
if (platformApplication != null) {
platformAppBuilder
.fileName(platformApplication.fileName())
.parameters(
Arrays.stream(platformApplication.parameters()).toList());
}

com.hedera.fullstack.junit.support.model.PlatformConfiguration.Builder platformConfigBuilder =
new com.hedera.fullstack.junit.support.model.PlatformConfiguration.Builder();
if (platformConfigurations != null) {
Stream.of(platformConfigurations.value())
.forEach(config ->
// FUTURE: support values[]
platformConfigBuilder.addConfigurationValue(
new ConfigurationValue(config.name(), config.value())));
}

// Topology holds all the information needed to provision
NetworkDeploymentConfiguration networkDeploymentConfiguration = new NetworkDeploymentConfiguration.Builder()
.applicationNodes(appNodesBuilder.build())
.platformApplication(platformAppBuilder.build())
.platformConfiguration(platformConfigBuilder.build())
.build();
// FUTURE: provision this topology using test tool kit here
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.fullstack.junit.support.model;

public record ApplicationNodes(int values, ResourceShape shape) {

public static class Builder {
private int value;
private ResourceShape shape;

public Builder value(int value) {
this.value = value;
return this;
}

public Builder shape(ResourceShape shape) {
this.shape = shape;
return this;
}

public ApplicationNodes build() {
return new ApplicationNodes(value, shape);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.fullstack.junit.support.model;

public record ConfigurationValue(String name, String value) {

public static class Builder {
private String name;
private String value;

public Builder name(String name) {
this.name = name;
return this;
}

public Builder value(String value) {
this.value = value;
return this;
}

public ConfigurationValue build() {
return new ConfigurationValue(name, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.fullstack.junit.support.model;

public record NetworkDeploymentConfiguration(
ApplicationNodes applicationNodes,
PlatformConfiguration platformConfiguration,
PlatformApplication platformApplication) {

public static class Builder {
private ApplicationNodes applicationNodes;
private PlatformConfiguration platformConfiguration;
private PlatformApplication platformApplication;

public Builder applicationNodes(ApplicationNodes applicationNodes) {
this.applicationNodes = applicationNodes;
return this;
}

public Builder platformConfiguration(PlatformConfiguration platformConfiguration) {
this.platformConfiguration = platformConfiguration;
return this;
}

public Builder platformApplication(PlatformApplication platformApplication) {
this.platformApplication = platformApplication;
return this;
}

public NetworkDeploymentConfiguration build() {
return new NetworkDeploymentConfiguration(applicationNodes, platformConfiguration, platformApplication);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.fullstack.junit.support.model;

import java.util.ArrayList;
import java.util.List;

public record PlatformApplication(String fileName, List<String> parameters) {

public static class Builder {
private String fileName;
private List<String> parameters = new ArrayList<>();

public Builder fileName(String fileName) {
this.fileName = fileName;
return this;
}

public Builder parameters(List<String> parameters) {
this.parameters = parameters;
return this;
}

public Builder addParameter(String parameter) {
this.parameters.add(parameter);
return this;
}

public PlatformApplication build() {
return new PlatformApplication(fileName, parameters);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.fullstack.junit.support.model;

import java.util.ArrayList;
import java.util.List;

public record PlatformConfiguration(List<ConfigurationValue> configurationValues) {

public static class Builder {
private List<ConfigurationValue> configurationValues = new ArrayList<>();

public Builder configurationValues(List<ConfigurationValue> configurationValues) {
this.configurationValues = configurationValues;
return this;
}

public Builder addConfigurationValue(ConfigurationValue configurationValue) {
this.configurationValues.add(configurationValue);
return this;
}

public PlatformConfiguration build() {
return new PlatformConfiguration(configurationValues);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed 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 com.hedera.fullstack.junit.support.model;

public record ResourceShape(float cpuInMillis) {

public static class Builder {
private float cpuInMillis;

public Builder cpuInMillis(float cpuInMillis) {
this.cpuInMillis = cpuInMillis;
return this;
}

public ResourceShape build() {
return new ResourceShape(cpuInMillis);
}
}
}

0 comments on commit 9c6930e

Please sign in to comment.