Search in sources :

Example 26 with Condition

use of org.assertj.core.api.Condition in project syndesis-qe by syndesisio.

the class SupportPageSteps method downloadAllLogs.

@When("^.*downloads? diagnostics for all integrations$")
public void downloadAllLogs() throws InterruptedException, IOException {
    supportPage.selectAllIntegrationDownload();
    File downloadedLogs = supportPage.downloadZipLogs();
    assertThat(downloadedLogs).exists().isFile().has(new Condition<>(f -> f.length() > 0, "File size should be greater than 0"));
    checkDownloadedFileContent(downloadedLogs);
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) Enumeration(java.util.Enumeration) When(io.cucumber.java.en.When) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Condition(org.assertj.core.api.Condition) SupportPage(io.syndesis.qe.pages.SupportPage) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) ZipFile(java.util.zip.ZipFile) File(java.io.File) When(io.cucumber.java.en.When)

Example 27 with Condition

use of org.assertj.core.api.Condition in project syndesis-qe by syndesisio.

the class SupportPageSteps method downloadSpecificLogs.

@When("^.*downloads? diagnostics for \"([^\"]*)\" integration$")
public void downloadSpecificLogs(String integrationName) throws InterruptedException, IOException {
    supportPage.selectSpecificIntegrationDownload(integrationName);
    File downloadedLogs = supportPage.downloadZipLogs();
    assertThat(downloadedLogs).exists().isFile().has(new Condition<>(f -> f.length() > 0, "File size should be greater than 0"));
    checkDownloadedFileContent(downloadedLogs);
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) Enumeration(java.util.Enumeration) When(io.cucumber.java.en.When) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Condition(org.assertj.core.api.Condition) SupportPage(io.syndesis.qe.pages.SupportPage) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) ZipFile(java.util.zip.ZipFile) File(java.io.File) When(io.cucumber.java.en.When)

Example 28 with Condition

use of org.assertj.core.api.Condition in project syndesis-qe by syndesisio.

the class SupportPageSteps method checkDownloadedFileContent.

private void checkDownloadedFileContent(File file) throws IOException {
    try (ZipFile zipFile = new ZipFile(file)) {
        assertThat(zipFile).has(new Condition<>(f -> f.size() > 4, "Inside of zip file should be at least 5 log files???"));
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            log.info("I found this file in downloaded zip: " + zipEntry.getName());
            assertThat(zipEntry).has(new Condition<>(f -> f.getSize() > 0, "Log file should not be empty!"));
        }
    }
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) Enumeration(java.util.Enumeration) When(io.cucumber.java.en.When) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Condition(org.assertj.core.api.Condition) SupportPage(io.syndesis.qe.pages.SupportPage) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry)

Example 29 with Condition

use of org.assertj.core.api.Condition in project cassandra by apache.

the class AbstractClientSizeWarning method failThreshold.

public void failThreshold(String cql) throws UnknownHostException {
    ICoordinator node = CLUSTER.coordinator(1);
    for (int i = 0; i < failThresholdRowCount(); i++) node.execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) VALUES (1, ?, ?)", ConsistencyLevel.ALL, i + 1, bytes(512));
    if (shouldFlush())
        CLUSTER.stream().forEach(i -> i.flush(KEYSPACE));
    enable(true);
    checkpointHistogram();
    List<String> warnings = CLUSTER.get(1).callsOnInstance(() -> {
        ClientWarn.instance.captureWarnings();
        CoordinatorWarnings.init();
        try {
            QueryProcessor.execute(cql, org.apache.cassandra.db.ConsistencyLevel.ALL, QueryState.forInternalCalls());
            Assert.fail("Expected query failure");
        } catch (ReadSizeAbortException e) {
        // expected, client transport returns an error message and includes client warnings
        }
        CoordinatorWarnings.done();
        CoordinatorWarnings.reset();
        return ClientWarn.instance.getWarnings();
    }).call();
    assertAbortWarnings(warnings);
    assertHistogramUpdated();
    assertWarnAborts(0, 1, 1);
    try {
        driverQueryAll(cql);
        Assert.fail("Query should have thrown ReadFailureException");
    } catch (com.datastax.driver.core.exceptions.ReadFailureException e) {
        // without changing the client can't produce a better message...
        // client does NOT include the message sent from the server in the exception; so the message doesn't work
        // well in this case
        assertThat(e.getMessage()).contains("responses were required but only 0 replica responded");
        ImmutableSet<InetAddress> expectedKeys = ImmutableSet.of(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
        assertThat(e.getFailuresMap()).hasSizeBetween(1, 3).containsValue(RequestFailureReason.READ_SIZE.code).hasKeySatisfying(new Condition<InetAddress>() {

            public boolean matches(InetAddress value) {
                return expectedKeys.contains(value);
            }
        });
    }
    assertHistogramUpdated();
    assertWarnAborts(0, 2, 1);
    // query should no longer fail
    enable(false);
    SimpleQueryResult result = node.executeWithResult(cql, ConsistencyLevel.ALL);
    assertThat(result.warnings()).isEmpty();
    assertHistogramNotUpdated();
    assertThat(driverQueryAll(cql).getExecutionInfo().getWarnings()).isEmpty();
    assertHistogramNotUpdated();
    assertWarnAborts(0, 2, 0);
}
Also used : Arrays(java.util.Arrays) SimpleStatement(com.datastax.driver.core.SimpleStatement) BeforeClass(org.junit.BeforeClass) ClientWarn(org.apache.cassandra.service.ClientWarn) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) JavaDriverUtils(org.apache.cassandra.distributed.test.JavaDriverUtils) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) ResultSet(com.datastax.driver.core.ResultSet) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) TestBaseImpl(org.apache.cassandra.distributed.test.TestBaseImpl) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Before(org.junit.Before) Feature(org.apache.cassandra.distributed.api.Feature) CoordinatorWarnings(org.apache.cassandra.service.reads.trackwarnings.CoordinatorWarnings) ImmutableSet(com.google.common.collect.ImmutableSet) QueryState(org.apache.cassandra.service.QueryState) ReadSizeAbortException(org.apache.cassandra.exceptions.ReadSizeAbortException) ICluster(org.apache.cassandra.distributed.api.ICluster) IOException(java.io.IOException) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) UnknownHostException(java.net.UnknownHostException) Consumer(java.util.function.Consumer) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Condition(org.assertj.core.api.Condition) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Collections(java.util.Collections) Condition(org.assertj.core.api.Condition) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) SimpleQueryResult(org.apache.cassandra.distributed.api.SimpleQueryResult) ReadSizeAbortException(org.apache.cassandra.exceptions.ReadSizeAbortException) ImmutableSet(com.google.common.collect.ImmutableSet) InetAddress(java.net.InetAddress)

Example 30 with Condition

use of org.assertj.core.api.Condition in project mockito by mockito.

the class Conditions method bridgeMethod.

public static Condition<Object> bridgeMethod(final String methodName) {
    return new Condition<Object>() {

        public boolean matches(Object o) {
            Class<?> clazz = null;
            if (o instanceof Class) {
                clazz = (Class<?>) o;
            } else {
                clazz = o.getClass();
            }
            for (Method m : clazz.getMethods()) {
                if (m.isBridge() && m.getName().equals(methodName)) {
                    return true;
                }
            }
            Assertions.fail("Bridge method [" + methodName + "]\nnot found in:\n" + o);
            return false;
        }
    };
}
Also used : Condition(org.assertj.core.api.Condition) Method(java.lang.reflect.Method)

Aggregations

Condition (org.assertj.core.api.Condition)33 Test (org.junit.Test)19 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 List (java.util.List)9 Before (org.junit.Before)7 File (java.io.File)5 IOException (java.io.IOException)5 Arrays (java.util.Arrays)5 ExecutorService (java.util.concurrent.ExecutorService)4 Assertions (org.assertj.core.api.Assertions)4 Rule (org.junit.Rule)4 Mock (org.mockito.Mock)4 When (io.cucumber.java.en.When)3 SupportPage (io.syndesis.qe.pages.SupportPage)3 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Enumeration (java.util.Enumeration)3 TimeUnit (java.util.concurrent.TimeUnit)3 ZipEntry (java.util.zip.ZipEntry)3