Search in sources :

Example 1 with Assert.fail

use of org.junit.Assert.fail in project bookkeeper by apache.

the class BookieWriteLedgerTest method testLedgerCreateAdvWithLedgerIdInLoop.

/**
 * In a loop create/write/delete the ledger with same ledgerId through
 * the functionality of Advanced Ledger which accepts ledgerId as input.
 *
 * @throws Exception
 */
@Test
public void testLedgerCreateAdvWithLedgerIdInLoop() throws Exception {
    int ledgerCount = 40;
    long maxId = 9999999999L;
    if (baseConf.getLedgerManagerFactoryClass().equals(LongHierarchicalLedgerManagerFactory.class)) {
        // since LongHierarchicalLedgerManager supports ledgerIds of decimal length upto 19 digits but other
        // LedgerManagers only upto 10 decimals
        maxId = Long.MAX_VALUE;
    }
    // generate a stream of ledger ids
    rng.longs(ledgerCount, 0, maxId).mapToObj(ledgerId -> {
        // create a ledger for each ledger id
        LOG.info("Creating adv ledger with id {}", ledgerId);
        return bkc.newCreateLedgerOp().withEnsembleSize(1).withWriteQuorumSize(1).withAckQuorumSize(1).withDigestType(org.apache.bookkeeper.client.api.DigestType.CRC32).withPassword(ledgerPassword).makeAdv().withLedgerId(ledgerId).execute().thenApply(writer -> {
            // Add entries to ledger when created
            LOG.info("Writing stream of {} entries to {}", numEntriesToWrite, ledgerId);
            List<ByteBuf> entries = rng.ints(numEntriesToWrite, 0, maxInt).mapToObj(i -> {
                ByteBuf entry = Unpooled.buffer(4);
                entry.retain();
                entry.writeInt(i);
                return entry;
            }).collect(Collectors.toList());
            CompletableFuture<?> lastRequest = null;
            int i = 0;
            for (ByteBuf entry : entries) {
                long entryId = i++;
                LOG.info("Writing {}:{} as {}", ledgerId, entryId, entry.slice().readInt());
                lastRequest = writer.writeAsync(entryId, entry);
            }
            lastRequest.join();
            return Pair.of(writer, entries);
        });
    }).parallel().map(// wait for all creations and adds in parallel
    CompletableFuture::join).forEach(e -> {
        // check that each set of adds succeeded
        try {
            WriteAdvHandle handle = e.getLeft();
            List<ByteBuf> entries = e.getRight();
            // Read and verify
            LOG.info("Read entries for ledger: {}", handle.getId());
            readEntries(handle, entries);
            entries.forEach(ByteBuf::release);
            handle.close();
            bkc.deleteLedger(handle.getId());
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            Assert.fail("Test interrupted");
        } catch (Exception ex) {
            LOG.info("Readback failed with exception", ex);
            Assert.fail("Readback failed " + ex.getMessage());
        }
    });
}
Also used : BKLedgerClosedException(org.apache.bookkeeper.client.BKException.BKLedgerClosedException) Whitebox(org.powermock.reflect.Whitebox) BookKeeperClusterTestCase(org.apache.bookkeeper.test.BookKeeperClusterTestCase) ADD_OP_UR(org.apache.bookkeeper.client.BookKeeperClientStats.ADD_OP_UR) Enumeration(java.util.Enumeration) LoggerFactory(org.slf4j.LoggerFactory) READ_OP_DM(org.apache.bookkeeper.client.BookKeeperClientStats.READ_OP_DM) HashMap(java.util.HashMap) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) CLIENT_SCOPE(org.apache.bookkeeper.client.BookKeeperClientStats.CLIENT_SCOPE) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ADD_OP(org.apache.bookkeeper.client.BookKeeperClientStats.ADD_OP) Assert.fail(org.junit.Assert.fail) Bookie(org.apache.bookkeeper.bookie.Bookie) BookieException(org.apache.bookkeeper.bookie.BookieException) Before(org.junit.Before) AddCallback(org.apache.bookkeeper.client.AsyncCallback.AddCallback) DigestType(org.apache.bookkeeper.client.BookKeeper.DigestType) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) LongHierarchicalLedgerManagerFactory(org.apache.bookkeeper.meta.LongHierarchicalLedgerManagerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ExecutionException(java.util.concurrent.ExecutionException) ReadHandle(org.apache.bookkeeper.client.api.ReadHandle) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) WriteAdvHandle(org.apache.bookkeeper.client.api.WriteAdvHandle) Assert(org.junit.Assert) LedgerEntries(org.apache.bookkeeper.client.api.LedgerEntries) Assert.assertEquals(org.junit.Assert.assertEquals) WriteAdvHandle(org.apache.bookkeeper.client.api.WriteAdvHandle) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) ByteBuf(io.netty.buffer.ByteBuf) BKLedgerClosedException(org.apache.bookkeeper.client.BKException.BKLedgerClosedException) BookieException(org.apache.bookkeeper.bookie.BookieException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with Assert.fail

use of org.junit.Assert.fail in project open-kilda by telstra.

the class StatsTopologyTest method flowAttendantRulesStatsTest.

@Test
public void flowAttendantRulesStatsTest() {
    Flow flow = createFlow();
    FlowSegmentCookie server42IngressCookie = MAIN_FORWARD_COOKIE.toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build();
    FlowEndpoint ingress = new FlowEndpoint(SWITCH_ID_1, PORT_1);
    FlowStatsEntry measure0 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 0, 0, ingress.getPortNumber(), ingress.getPortNumber() + 1);
    FlowStatsEntry measure1 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 1, 200, ingress.getPortNumber(), ingress.getPortNumber() + 1);
    FlowStatsEntry measure2 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 2, 300, ingress.getPortNumber(), ingress.getPortNumber() + 1);
    sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure0)));
    sendUpdateFlowPathInfo(flow.getForwardPath());
    sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure1)));
    sendRemoveFlowPathInfo(flow.getForwardPath());
    sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure2)));
    List<Datapoint> datapoints = pollDatapoints(9);
    List<Datapoint> rawPacketsMetric = datapoints.stream().filter(entry -> (METRIC_PREFIX + "flow.raw.packets").equals(entry.getMetric())).collect(Collectors.toList());
    Assert.assertEquals(3, rawPacketsMetric.size());
    for (Datapoint entry : rawPacketsMetric) {
        Map<String, String> tags = entry.getTags();
        Assert.assertEquals(CookieType.SERVER_42_FLOW_RTT_INGRESS.name().toLowerCase(), tags.get("type"));
        if (Objects.equals(0, entry.getValue())) {
            Assert.assertEquals("unknown", tags.get("flowid"));
        } else if (Objects.equals(1, entry.getValue())) {
            Assert.assertEquals(flowId, tags.get("flowid"));
        } else if (Objects.equals(2, entry.getValue())) {
            Assert.assertEquals("unknown", tags.get("flowid"));
        } else {
            Assert.fail(format("Unexpected metric value: %s", entry));
        }
    }
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) CoreMatchers.is(org.hamcrest.CoreMatchers.is) InfoMessage(org.openkilda.messaging.info.InfoMessage) Arrays(java.util.Arrays) FlowPath(org.openkilda.model.FlowPath) GetPacketInOutStatsResponse(org.openkilda.messaging.info.grpc.GetPacketInOutStatsResponse) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Utils.sleep(org.apache.storm.utils.Utils.sleep) Flow(org.openkilda.model.Flow) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowRttStatsData(org.openkilda.messaging.info.stats.FlowRttStatsData) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) AfterClass(org.junit.AfterClass) LaunchEnvironment(org.openkilda.wfm.LaunchEnvironment) FORWARD(org.openkilda.model.FlowPathDirection.FORWARD) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) InfoData(org.openkilda.messaging.info.InfoData) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) UUID(java.util.UUID) Datapoint(org.openkilda.messaging.info.Datapoint) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) UpdateFlowPathInfo(org.openkilda.messaging.info.stats.UpdateFlowPathInfo) Objects(java.util.Objects) List(java.util.List) MeterStatsEntry(org.openkilda.messaging.info.stats.MeterStatsEntry) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Config(org.apache.storm.Config) REVERSE(org.openkilda.model.FlowPathDirection.REVERSE) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) IntStream(java.util.stream.IntStream) BeforeClass(org.junit.BeforeClass) STATS_TOPOLOGY_TEST_ZOOKEEPER_PORT(org.openkilda.wfm.config.ZookeeperConfig.STATS_TOPOLOGY_TEST_ZOOKEEPER_PORT) HashMap(java.util.HashMap) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) Function(java.util.function.Function) ArrayList(java.util.ArrayList) RemoveFlowPathInfo(org.openkilda.messaging.info.stats.RemoveFlowPathInfo) SwitchTableStatsData(org.openkilda.messaging.info.stats.SwitchTableStatsData) ImmutableList(com.google.common.collect.ImmutableList) StormTopology(org.apache.storm.generated.StormTopology) TableStatsEntry(org.openkilda.messaging.info.stats.TableStatsEntry) Cookie(org.openkilda.model.cookie.Cookie) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) TestFlowBuilder(org.openkilda.wfm.share.flow.TestFlowBuilder) Before(org.junit.Before) InMemoryGraphPersistenceManager(org.openkilda.persistence.inmemory.InMemoryGraphPersistenceManager) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) STATS_TOPOLOGY_TEST_KAFKA_PORT(org.openkilda.wfm.config.KafkaConfig.STATS_TOPOLOGY_TEST_KAFKA_PORT) Switch(org.openkilda.model.Switch) Properties(java.util.Properties) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) MeterId(org.openkilda.model.MeterId) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) SwitchId(org.openkilda.model.SwitchId) Ignore(org.junit.Ignore) PacketInOutStatsDto(org.openkilda.messaging.model.grpc.PacketInOutStatsDto) Destination(org.openkilda.messaging.Destination) TestKafkaConsumer(org.openkilda.wfm.topology.TestKafkaConsumer) VERIFICATION_BROADCAST_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_BROADCAST_RULE_COOKIE) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) Flow(org.openkilda.model.Flow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 3 with Assert.fail

use of org.junit.Assert.fail in project graal by oracle.

the class SLExceptionTest method assertException.

private void assertException(boolean failImmediately, String source, String... expectedFrames) {
    boolean initialExecute = true;
    try {
        Value value = ctx.eval("sl", source);
        initialExecute = false;
        if (failImmediately) {
            Assert.fail("Should not reach here.");
        }
        ProxyExecutable proxy = (args) -> args[0].execute();
        value.execute(proxy);
        Assert.fail("Should not reach here.");
    } catch (PolyglotException e) {
        Assert.assertEquals(failImmediately, initialExecute);
        assertFrames(failImmediately, e, expectedFrames);
    }
}
Also used : Iterator(java.util.Iterator) PolyglotException(org.graalvm.polyglot.PolyglotException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Value(org.graalvm.polyglot.Value) Assert.assertNotSame(org.junit.Assert.assertNotSame) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Source(org.graalvm.polyglot.Source) After(org.junit.After) ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Assert.fail(org.junit.Assert.fail) Context(org.graalvm.polyglot.Context) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Value(org.graalvm.polyglot.Value) PolyglotException(org.graalvm.polyglot.PolyglotException)

Example 4 with Assert.fail

use of org.junit.Assert.fail in project graal by oracle.

the class SLExceptionTest method assertHostException.

private void assertHostException(String source, String... expectedFrames) {
    boolean initialExecute = true;
    RuntimeException[] exception = new RuntimeException[1];
    try {
        Value value = ctx.eval("sl", source);
        initialExecute = false;
        ProxyExecutable proxy = (args) -> {
            throw exception[0] = new RuntimeException();
        };
        value.execute(proxy);
        Assert.fail("Should not reach here.");
    } catch (PolyglotException e) {
        Assert.assertFalse(initialExecute);
        Assert.assertTrue(e.asHostException() == exception[0]);
        assertFrames(false, e, expectedFrames);
    }
}
Also used : Iterator(java.util.Iterator) PolyglotException(org.graalvm.polyglot.PolyglotException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Value(org.graalvm.polyglot.Value) Assert.assertNotSame(org.junit.Assert.assertNotSame) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StackFrame(org.graalvm.polyglot.PolyglotException.StackFrame) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Source(org.graalvm.polyglot.Source) After(org.junit.After) ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Assert.fail(org.junit.Assert.fail) Context(org.graalvm.polyglot.Context) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Value(org.graalvm.polyglot.Value) PolyglotException(org.graalvm.polyglot.PolyglotException)

Aggregations

ArrayList (java.util.ArrayList)4 List (java.util.List)4 Assert (org.junit.Assert)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.fail (org.junit.Assert.fail)4 Before (org.junit.Before)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Context (org.graalvm.polyglot.Context)2 PolyglotException (org.graalvm.polyglot.PolyglotException)2 StackFrame (org.graalvm.polyglot.PolyglotException.StackFrame)2 Source (org.graalvm.polyglot.Source)2 Value (org.graalvm.polyglot.Value)2 ProxyExecutable (org.graalvm.polyglot.proxy.ProxyExecutable)2 After (org.junit.After)2