Search in sources :

Example 1 with Table

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);
    }
}
Also used : AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Random(java.util.Random) EthBlockNumber(org.web3j.protocol.core.methods.response.EthBlockNumber) ArrayList(java.util.ArrayList) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) BigInteger(java.math.BigInteger) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) InfrastructureService(com.quorum.gauge.services.InfrastructureService) QuorumNode(com.quorum.gauge.common.QuorumNode) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) Collectors(java.util.stream.Collectors) ContractService(com.quorum.gauge.services.ContractService) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) NetworkResources(com.quorum.gauge.services.InfrastructureService.NetworkResources) NotNull(org.jetbrains.annotations.NotNull) Table(com.thoughtworks.gauge.Table) NetworkResources(com.quorum.gauge.services.InfrastructureService.NetworkResources) Step(com.thoughtworks.gauge.Step)

Example 2 with Table

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);
    }
}
Also used : AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Random(java.util.Random) EthBlockNumber(org.web3j.protocol.core.methods.response.EthBlockNumber) ArrayList(java.util.ArrayList) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) BigInteger(java.math.BigInteger) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) Contract(org.web3j.tx.Contract) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) InfrastructureService(com.quorum.gauge.services.InfrastructureService) QuorumNode(com.quorum.gauge.common.QuorumNode) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) Collectors(java.util.stream.Collectors) ContractService(com.quorum.gauge.services.ContractService) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) NetworkResources(com.quorum.gauge.services.InfrastructureService.NetworkResources) NotNull(org.jetbrains.annotations.NotNull) Table(com.thoughtworks.gauge.Table) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) NetworkResources(com.quorum.gauge.services.InfrastructureService.NetworkResources) Step(com.thoughtworks.gauge.Step)

Example 3 with Table

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);
            }
        }
    });
}
Also used : AbstractSpecImplementation(com.quorum.gauge.core.AbstractSpecImplementation) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Step(com.thoughtworks.gauge.Step) Logger(org.slf4j.Logger) ObjectResponse(com.quorum.gauge.ext.ObjectResponse) QuorumNode(com.quorum.gauge.common.QuorumNode) BatchRequest(com.quorum.gauge.ext.BatchRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) LoggerFactory(org.slf4j.LoggerFactory) Response(org.web3j.protocol.core.Response) Collectors(java.util.stream.Collectors) Request(org.web3j.protocol.core.Request) Stream(java.util.stream.Stream) Context(com.quorum.gauge.common.Context) Service(org.springframework.stereotype.Service) Table(com.thoughtworks.gauge.Table) DataStoreFactory(com.thoughtworks.gauge.datastore.DataStoreFactory) ObjectResponse(com.quorum.gauge.ext.ObjectResponse) Response(org.web3j.protocol.core.Response) BatchRequest(com.quorum.gauge.ext.BatchRequest) BatchRequest(com.quorum.gauge.ext.BatchRequest) Request(org.web3j.protocol.core.Request) ObjectResponse(com.quorum.gauge.ext.ObjectResponse) Step(com.thoughtworks.gauge.Step)

Example 4 with Table

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));
}
Also used : Messages(gauge.messages.Messages) StepRegistry(com.thoughtworks.gauge.registry.StepRegistry) Table(com.thoughtworks.gauge.Table) ClassInstanceManager(com.thoughtworks.gauge.ClassInstanceManager) Method(java.lang.reflect.Method) Spec(gauge.messages.Spec) ParameterParsingChain(com.thoughtworks.gauge.execution.parameters.parsers.base.ParameterParsingChain)

Example 5 with Table

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;
}
Also used : Table(com.thoughtworks.gauge.Table) Spec(gauge.messages.Spec)

Aggregations

Table (com.thoughtworks.gauge.Table)5 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)3 QuorumNode (com.quorum.gauge.common.QuorumNode)3 AbstractSpecImplementation (com.quorum.gauge.core.AbstractSpecImplementation)3 Step (com.thoughtworks.gauge.Step)3 DataStoreFactory (com.thoughtworks.gauge.datastore.DataStoreFactory)3 Collectors (java.util.stream.Collectors)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Service (org.springframework.stereotype.Service)3 ContractService (com.quorum.gauge.services.ContractService)2 InfrastructureService (com.quorum.gauge.services.InfrastructureService)2 NetworkResources (com.quorum.gauge.services.InfrastructureService.NetworkResources)2 Spec (gauge.messages.Spec)2 Observable (io.reactivex.Observable)2 Schedulers (io.reactivex.schedulers.Schedulers)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2