use of com.thoughtworks.gauge.Table in project quorum-acceptance-tests by ConsenSys.
the class NetworkMigration method restartNetwork.
/**
* When restarting the network, we destroy the currrent containers and recreate new ones with new images
* Datadir will not be deleted as it lives in the volume
*
* @param table
*/
@Step("Restart the network with: <table>")
public void restartNetwork(Table table) {
NetworkResources existingNetworkResources = mustHaveValue(DataStoreFactory.getScenarioDataStore(), "networkResources", NetworkResources.class);
infraService.deleteNetwork(existingNetworkResources).blockingSubscribe();
NetworkResources networkResources = new NetworkResources();
try {
Observable.fromIterable(table.getTableRows()).flatMap(r -> infraService.startNode(InfrastructureService.NodeAttributes.forNode(r.getCell("node")).withQuorumVersionKey(r.getCell("quorum")).withTesseraVersionKey(r.getCell("tessera")), resourceId -> networkResources.add(r.getCell("node"), resourceId))).doOnNext(ok -> {
assertThat(ok).as("Node must be restarted successfully").isTrue();
}).doOnComplete(() -> {
logger.debug("Waiting for network to be up completely...");
Thread.sleep(networkProperty.getConsensusGracePeriod().toMillis());
}).blockingSubscribe();
} finally {
DataStoreFactory.getScenarioDataStore().put("networkResources", networkResources);
}
}
use of com.thoughtworks.gauge.Table in project quorum-acceptance-tests by ConsenSys.
the class NetworkMigration method startNetwork.
@Step("Start the network with: <table>")
public void startNetwork(Table table) {
NetworkResources networkResources = new NetworkResources();
try {
Observable.fromIterable(table.getTableRows()).flatMap(r -> infraService.startNode(InfrastructureService.NodeAttributes.forNode(r.getCell("node")).withQuorumVersionKey(r.getCell("quorum")).withTesseraVersionKey(r.getCell("tessera")), resourceId -> networkResources.add(r.getCell("node"), resourceId))).doOnNext(ok -> {
assertThat(ok).as("Node must start successfully").isTrue();
}).blockingSubscribe();
var nodes = table.getTableRows().stream().map(r -> networkProperty.getNode(r.getCell("node"))).toArray(QuorumNetworkProperty.Node[]::new);
utilService.waitForNodesToReach(networkProperty.getConsensusBlockHeight(), nodes);
} finally {
DataStoreFactory.getScenarioDataStore().put("networkResources", networkResources);
}
}
use of com.thoughtworks.gauge.Table in project quorum-acceptance-tests by ConsenSys.
the class PluginSecurity method invokeMultipleWithExpectation.
@Step("`<clientId>` sends a batch `<apis>` to `<node>` and expect: <table>")
public void invokeMultipleWithExpectation(String clientId, String apis, QuorumNetworkProperty.Node node, Table table) {
String token = mustHaveValue(DataStoreFactory.getScenarioDataStore(), clientId, String.class);
Context.storeAccessToken(token);
BatchRequest.Collector collector = BatchRequest.Collector.create();
Arrays.stream(apis.split(",")).map(String::trim).forEach(n -> collector.add(n, Collections.emptyList()));
Map<String, String> expect = table.getTableRows().stream().collect(Collectors.toMap(r -> StringUtils.removeEnd(StringUtils.removeStart(r.getCell("callApi"), "`"), "`"), r -> r.getCell("expectation")));
rpcService.call(node, collector).blockingForEach(batchResponse -> {
assertThat(batchResponse.getResponses()).as("Number of returned responses").hasSize(collector.size());
for (ObjectResponse res : batchResponse.getResponses()) {
assertThat(res.getId()).as("Response must have id").isNotZero();
Request r = collector.getByID(res.getId());
String policy = Optional.ofNullable(expect.get(r.getMethod())).orElseThrow(() -> new IllegalStateException("no such method in expectation table: " + r.getMethod()));
boolean expectAuthorized = "success".equalsIgnoreCase(policy);
String description = policy + ": " + r.getMethod() + "@" + node.getName();
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
}
});
}
use of com.thoughtworks.gauge.Table in project gauge-java by getgauge.
the class StepExecutionStageTest method testStepMethodExecutionCanBeCalledAsObjectForSpecialTable.
public void testStepMethodExecutionCanBeCalledAsObjectForSpecialTable() throws Exception {
Spec.Parameter tableParameter = Spec.Parameter.newBuilder().setValue("table { headers {cells: \"Id\"}rows {cells: \"1\"}}").setName("table").setParameterType(Spec.Parameter.ParameterType.Special_Table).build();
Messages.ExecuteStepRequest executeStepRequest = Messages.ExecuteStepRequest.newBuilder().setParsedStepText("hello {}").setActualStepText("hello <table>").addParameters(tableParameter).build();
StepExecutionStage executionStage = new StepExecutionStage(executeStepRequest, new ClassInstanceManager(), new ParameterParsingChain(), mock(StepRegistry.class));
MethodExecutor methodExecutor = mock(MethodExecutor.class);
Method tableMethod = this.getClass().getMethod("table", Object.class);
executionStage.executeStepMethod(methodExecutor, tableMethod);
verify(methodExecutor, times(1)).execute(eq(tableMethod), isA(Table.class));
}
use of com.thoughtworks.gauge.Table in project gauge-java by getgauge.
the class TableConverter method tableFromProto.
private Object tableFromProto(Spec.ProtoTable protoTable) {
if (protoTable.getHeaders() == null) {
throw new RuntimeException("Invalid table passed");
}
Spec.ProtoTableRow headerRow = protoTable.getHeaders();
List<String> headers = getTableRowFor(headerRow);
Table table = new Table(headers);
for (int i = 0; i < protoTable.getRowsCount(); i++) {
Spec.ProtoTableRow protoRow = protoTable.getRows(i);
table.addRow(getTableRowFor(protoRow));
}
return table;
}
Aggregations