Search in sources :

Example 6 with Utf8Array

use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.

the class RPCSendV1 method createReply.

@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
    Version version = new Version(ret.get(0).asUtf8Array());
    double retryDelay = ret.get(1).asDouble();
    int[] errorCodes = ret.get(2).asInt32Array();
    String[] errorMessages = ret.get(3).asStringArray();
    String[] errorServices = ret.get(4).asStringArray();
    Utf8Array protocolName = ret.get(5).asUtf8Array();
    byte[] payload = ret.get(6).asData();
    String replyTrace = ret.get(7).asString();
    // Make sure that the owner understands the protocol.
    Reply reply = null;
    Error error = null;
    if (payload.length > 0) {
        Object retval = decode(protocolName, version, payload);
        if (retval instanceof Reply) {
            reply = (Reply) retval;
        } else {
            error = (Error) retval;
        }
    }
    if (reply == null) {
        reply = new EmptyReply();
    }
    if (error != null) {
        reply.addError(error);
    }
    reply.setRetryDelay(retryDelay);
    for (int i = 0; i < errorCodes.length && i < errorMessages.length; i++) {
        reply.addError(new Error(errorCodes[i], errorMessages[i], errorServices[i].length() > 0 ? errorServices[i] : serviceName));
    }
    if (trace.getLevel() > 0) {
        trace.getRoot().addChild(TraceNode.decode(replyTrace));
    }
    return reply;
}
Also used : Version(com.yahoo.component.Version) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 7 with Utf8Array

use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.

the class ByteWriterTestCase method testWriteUtf8Array.

public void testWriteUtf8Array() throws IOException {
    stream.reset();
    ByteWriter b = new ByteWriter(stream, encoder);
    final byte[] bytes = Utf8.toBytes("nalle");
    b.write(new Utf8Array(bytes));
    b.close();
    assertArrayEquals(bytes, stream.toByteArray());
}
Also used : Utf8Array(com.yahoo.text.Utf8Array)

Example 8 with Utf8Array

use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.

the class SerializationHelperTestCase method testGetNullTerminatedString.

public void testGetNullTerminatedString() throws Exception {
    // This is a test.0ab
    byte[] test = { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x0, 0x61, 0x62 };
    BufferSerializer data = BufferSerializer.wrap(test);
    assertTrue(data.position() == 0);
    Utf8Array thisIsATest = VespaDocumentDeserializer42.parseNullTerminatedString(data.getBuf().getByteBuffer());
    assertTrue(thisIsATest.equals(new Utf8Array(Utf8.toBytes("This is a test."))));
    assertTrue(data.position() == 16);
    // a
    assertTrue(test[16] == 0x61);
    data.position(0);
    assertTrue(data.position() == 0);
    Utf8Array thisIsATestAgain = VespaDocumentDeserializer42.parseNullTerminatedString(data.getBuf().getByteBuffer(), 15);
    assertTrue(thisIsATestAgain.equals(new Utf8Array(Utf8.toBytes("This is a test."))));
    assertTrue(data.position() == 16);
    // a
    assertTrue(test[16] == 0x61);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) Utf8Array(com.yahoo.text.Utf8Array)

Example 9 with Utf8Array

use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.

the class StoragePolicyTestEnvironment method setUp.

@Override
public void setUp() throws Exception {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:./test/cfg/testdoc.cfg");
    frame = new PolicyTestFrame(manager);
    nodes = new TreeSet<>();
    DocumentProtocol protocol = (DocumentProtocol) frame.getMessageBus().getProtocol((Utf8Array) DocumentProtocol.NAME);
    policyFactory = new StoragePolicyTestFactory(nodes);
    protocol.putRoutingPolicyFactory("storage", policyFactory);
    frame.setMessage(createMessage("userdoc:ns:1:foo"));
    frame.setHop(new HopSpec("test", "[storage:cluster=foo]"));
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) HopSpec(com.yahoo.messagebus.routing.HopSpec) PolicyTestFrame(com.yahoo.documentapi.messagebus.protocol.test.PolicyTestFrame) Utf8Array(com.yahoo.text.Utf8Array)

Example 10 with Utf8Array

use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.

the class ConfigPayload method toUtf8Array.

public Utf8Array toUtf8Array(boolean compact) {
    ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
    try {
        new JsonFormat(compact).encode(os, slime);
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new Utf8Array(os.toByteArray());
}
Also used : JsonFormat(com.yahoo.slime.JsonFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Utf8Array(com.yahoo.text.Utf8Array)

Aggregations

Utf8Array (com.yahoo.text.Utf8Array)15 Version (com.yahoo.component.Version)3 Slime (com.yahoo.slime.Slime)3 CompressionType (com.yahoo.compress.CompressionType)2 EmptyReply (com.yahoo.messagebus.EmptyReply)2 Error (com.yahoo.messagebus.Error)2 Reply (com.yahoo.messagebus.Reply)2 Inspector (com.yahoo.slime.Inspector)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)2 CompressionInfo (com.yahoo.vespa.config.protocol.CompressionInfo)2 SlimeConfigResponse (com.yahoo.vespa.config.protocol.SlimeConfigResponse)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 EqualsTester (com.google.common.testing.EqualsTester)1 DefParser (com.yahoo.config.codegen.DefParser)1 InnerCNode (com.yahoo.config.codegen.InnerCNode)1 DataTypeName (com.yahoo.document.DataTypeName)1 DocumentType (com.yahoo.document.DocumentType)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1