Search in sources :

Example 36 with FlatBufferBuilder

use of com.google.flatbuffers.FlatBufferBuilder in project deephaven-core by deephaven.

the class FlightMessageRoundTripTest method testDoExchangeSnapshot.

@Test
public void testDoExchangeSnapshot() throws Exception {
    final String staticTableName = "flightInfoTest";
    final Table table = TableTools.emptyTable(10).update("I = i", "J = i + 0.01");
    try (final SafeCloseable ignored = LivenessScopeStack.open(scriptSession, false)) {
        // stuff table into the scope
        scriptSession.setVariable(staticTableName, table);
        // build up a snapshot request
        // equivalent to '0x6E687064' (ASCII "dphn")
        byte[] magic = new byte[] { 100, 112, 104, 110 };
        FlightDescriptor fd = FlightDescriptor.command(magic);
        try (FlightClient.ExchangeReaderWriter erw = client.doExchange(fd);
            final RootAllocator allocator = new RootAllocator(Integer.MAX_VALUE)) {
            final FlatBufferBuilder metadata = new FlatBufferBuilder();
            int optOffset = BarrageSnapshotOptions.createBarrageSnapshotOptions(metadata, ColumnConversionMode.Stringify, false, 1000);
            final int ticOffset = BarrageSnapshotRequest.createTicketVector(metadata, ScopeTicketHelper.nameToBytes(staticTableName));
            BarrageSnapshotRequest.startBarrageSnapshotRequest(metadata);
            BarrageSnapshotRequest.addColumns(metadata, 0);
            BarrageSnapshotRequest.addViewport(metadata, 0);
            BarrageSnapshotRequest.addSnapshotOptions(metadata, optOffset);
            BarrageSnapshotRequest.addTicket(metadata, ticOffset);
            metadata.finish(BarrageSnapshotRequest.endBarrageSnapshotRequest(metadata));
            final FlatBufferBuilder wrapper = new FlatBufferBuilder();
            final int innerOffset = wrapper.createByteVector(metadata.dataBuffer());
            wrapper.finish(BarrageMessageWrapper.createBarrageMessageWrapper(wrapper, // the numerical representation of the ASCII "dphn".
            0x6E687064, BarrageMessageType.BarrageSnapshotRequest, innerOffset));
            // extract the bytes and package them in an ArrowBuf for transmission
            byte[] msg = wrapper.sizedByteArray();
            ArrowBuf data = allocator.buffer(msg.length);
            data.writeBytes(msg);
            erw.getWriter().putMetadata(data);
            erw.getWriter().completed();
            // read everything from the server (expecting schema message and one data message)
            int numMessages = 0;
            while (erw.getReader().next()) {
                ++numMessages;
            }
            // only one data message
            assertEquals(1, numMessages);
            // at this point should have the data, verify it matches the created table
            assertEquals(erw.getReader().getRoot().getRowCount(), table.size());
            // check the values against the source table
            org.apache.arrow.vector.IntVector iv = (org.apache.arrow.vector.IntVector) erw.getReader().getRoot().getVector(0);
            for (int i = 0; i < table.size(); i++) {
                assertEquals("int match:", table.getColumn(0).get(i), iv.get(i));
            }
            org.apache.arrow.vector.Float8Vector dv = (org.apache.arrow.vector.Float8Vector) erw.getReader().getRoot().getVector(1);
            for (int i = 0; i < table.size(); i++) {
                assertEquals("double match: ", table.getColumn(1).get(i), dv.get(i));
            }
        }
    }
}
Also used : Table(io.deephaven.engine.table.Table) ArrowBuf(org.apache.arrow.memory.ArrowBuf) RootAllocator(org.apache.arrow.memory.RootAllocator) FlatBufferBuilder(com.google.flatbuffers.FlatBufferBuilder) SafeCloseable(io.deephaven.util.SafeCloseable) Test(org.junit.Test)

Example 37 with FlatBufferBuilder

use of com.google.flatbuffers.FlatBufferBuilder in project deephaven-core by deephaven.

the class SchemaBytesImpl method toSchemaBytes.

@Override
public byte[] toSchemaBytes(TableHeader header) {
    final Schema schema = SchemaAdapter.of(header);
    final FlatBufferBuilder builder = new FlatBufferBuilder();
    final int schemaOffset = schema.getSchema(builder);
    final int messageOffset = MessageHelper.wrapInMessage(builder, schemaOffset, MessageHeader.Schema);
    builder.finish(messageOffset);
    return MessageHelper.toIpcBytes(builder);
}
Also used : Schema(org.apache.arrow.vector.types.pojo.Schema) FlatBufferBuilder(com.google.flatbuffers.FlatBufferBuilder)

Example 38 with FlatBufferBuilder

use of com.google.flatbuffers.FlatBufferBuilder in project apisix-java-plugin-runner by apache.

the class A6ConfigHandlerTest method testAddFilter1.

@Test
@DisplayName("test add filter by prepare conf")
void testAddFilter1() {
    FlatBufferBuilder builder = new FlatBufferBuilder();
    int name = builder.createString("FooFilter");
    int value = builder.createString("Bar");
    int conf = TextEntry.createTextEntry(builder, name, value);
    int confVector = Req.createConfVector(builder, new int[] { conf });
    Req.startReq(builder);
    Req.addConf(builder, confVector);
    builder.finish(Req.endReq(builder));
    Req req = Req.getRootAsReq(builder.dataBuffer());
    A6ConfigRequest request = new A6ConfigRequest(req);
    EmbeddedChannel channel = new EmbeddedChannel(new BinaryProtocolDecoder(), prepareConfHandler);
    channel.writeInbound(request);
    channel.finish();
    A6ConfigResponse response = channel.readOutbound();
    A6Conf config = cache.getIfPresent(response.getConfToken());
    Assertions.assertNotNull(config.getChain());
    Assertions.assertEquals(config.getChain().getFilters().size(), 1);
    Assertions.assertEquals(config.getChain().getIndex(), 0);
    Assertions.assertEquals(config.get("FooFilter"), "Bar");
}
Also used : A6ConfigRequest(org.apache.apisix.plugin.runner.A6ConfigRequest) A6ConfigResponse(org.apache.apisix.plugin.runner.A6ConfigResponse) FlatBufferBuilder(com.google.flatbuffers.FlatBufferBuilder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) A6Conf(org.apache.apisix.plugin.runner.A6Conf) Req(io.github.api7.A6.PrepareConf.Req) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 39 with FlatBufferBuilder

use of com.google.flatbuffers.FlatBufferBuilder in project apisix-java-plugin-runner by apache.

the class A6ConfigHandlerTest method testAddFilter4.

@Test
@DisplayName("test receive undefined filter")
void testAddFilter4() {
    FlatBufferBuilder builder = new FlatBufferBuilder();
    int foo = builder.createString("UndefinedFilter");
    int bar = builder.createString("Bar");
    int filter = TextEntry.createTextEntry(builder, foo, bar);
    int confVector = Req.createConfVector(builder, new int[] { filter });
    Req.startReq(builder);
    Req.addConf(builder, confVector);
    builder.finish(Req.endReq(builder));
    Req req = Req.getRootAsReq(builder.dataBuffer());
    A6ConfigRequest request = new A6ConfigRequest(req);
    EmbeddedChannel channel = new EmbeddedChannel(new BinaryProtocolDecoder(), prepareConfHandler);
    channel.writeInbound(request);
    channel.finish();
    A6ConfigResponse response = channel.readOutbound();
    A6Conf config = cache.getIfPresent(response.getConfToken());
    Assertions.assertEquals(config.getChain().getFilters().size(), 0);
}
Also used : A6ConfigRequest(org.apache.apisix.plugin.runner.A6ConfigRequest) A6ConfigResponse(org.apache.apisix.plugin.runner.A6ConfigResponse) FlatBufferBuilder(com.google.flatbuffers.FlatBufferBuilder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) A6Conf(org.apache.apisix.plugin.runner.A6Conf) Req(io.github.api7.A6.PrepareConf.Req) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 40 with FlatBufferBuilder

use of com.google.flatbuffers.FlatBufferBuilder in project apisix-java-plugin-runner by apache.

the class A6ConfigHandlerTest method testAddFilter5.

@Test
@DisplayName("test fetch conf more times")
void testAddFilter5() {
    FlatBufferBuilder builder = new FlatBufferBuilder();
    int name = builder.createString("FooFilter");
    int value = builder.createString("Bar");
    int conf = TextEntry.createTextEntry(builder, name, value);
    int confVector = Req.createConfVector(builder, new int[] { conf });
    Req.startReq(builder);
    Req.addConf(builder, confVector);
    builder.finish(Req.endReq(builder));
    Req req = Req.getRootAsReq(builder.dataBuffer());
    A6ConfigRequest request = new A6ConfigRequest(req);
    EmbeddedChannel channel = new EmbeddedChannel(new BinaryProtocolDecoder(), prepareConfHandler);
    channel.writeInbound(request);
    channel.finish();
    A6ConfigResponse response = channel.readOutbound();
    A6Conf a6Conf = cache.getIfPresent(response.getConfToken());
    Assertions.assertTrue(a6Conf.getConfig() instanceof HashMap);
    for (int i = 0; i < 100; i++) {
        Assertions.assertEquals(a6Conf.get("FooFilter"), "Bar");
    }
}
Also used : A6ConfigRequest(org.apache.apisix.plugin.runner.A6ConfigRequest) A6ConfigResponse(org.apache.apisix.plugin.runner.A6ConfigResponse) HashMap(java.util.HashMap) FlatBufferBuilder(com.google.flatbuffers.FlatBufferBuilder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) A6Conf(org.apache.apisix.plugin.runner.A6Conf) Req(io.github.api7.A6.PrepareConf.Req) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

FlatBufferBuilder (com.google.flatbuffers.FlatBufferBuilder)51 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 BigInteger (java.math.BigInteger)10 A6ConfigRequest (org.apache.apisix.plugin.runner.A6ConfigRequest)9 HttpRequest (org.apache.apisix.plugin.runner.HttpRequest)9 ByteBuffer (java.nio.ByteBuffer)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 A6ConfigResponse (org.apache.apisix.plugin.runner.A6ConfigResponse)7 Test (org.junit.Test)7 Req (io.github.api7.A6.PrepareConf.Req)5 A6Conf (org.apache.apisix.plugin.runner.A6Conf)5 ByteStringAccess (com.google.protobuf.ByteStringAccess)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 UncheckedDeephavenException (io.deephaven.UncheckedDeephavenException)3 ChunkType (io.deephaven.chunk.ChunkType)3 Map (java.util.Map)3 lombok.val (lombok.val)3 ExtraInfoRequest (org.apache.apisix.plugin.runner.ExtraInfoRequest)3 BaseNd4jTest (org.nd4j.linalg.BaseNd4jTest)3