aboutsummaryrefslogtreecommitdiffstats
path: root/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerBasicTestCase.java
blob: 6a4729002c42a8a29011eb345141625025e300b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.docproc.jdisc;

import com.yahoo.collections.Pair;
import com.yahoo.docproc.CallStack;
import com.yahoo.docproc.SimpleDocumentProcessor;
import com.yahoo.document.DataType;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentType;
import com.yahoo.document.Field;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage;
import com.yahoo.messagebus.Message;
import com.yahoo.messagebus.Reply;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
public class DocumentProcessingHandlerBasicTestCase extends DocumentProcessingHandlerTestBase {
    private DocumentType type;

    public DocumentProcessingHandlerBasicTestCase() {
        this.type = new DocumentType("yalla");
        this.type.addField(new Field("blahblah", DataType.STRING));
    }

    @Test
    public void testPut() throws InterruptedException {
        Document document = new Document(getType(), "id:ns:yalla::balla");
        document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
        PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));

        assertTrue(sendMessage("foobar", message));

        Message msg = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
        assertNotNull(msg);
        remoteServer.ackMessage(msg);
        Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
        assertNotNull(reply);

        assertTrue((msg instanceof PutDocumentMessage));
        PutDocumentMessage put = (PutDocumentMessage) msg;
        Document outDoc = put.getDocumentPut().getDocument();

        assertEquals(document, outDoc);
        assertFalse(reply.hasErrors());
    }

    @Override
    public List<Pair<String,CallStack>> getCallStacks() {
        CallStack stack = new CallStack();
        stack.addLast(new TestDocumentProcessor());

        ArrayList<Pair<String, CallStack>> stacks = new ArrayList<>(1);
        stacks.add(new Pair<>("foobar", stack));
        return stacks;
    }

    @Override
    public DocumentType getType() {
        return type;
    }

    public static class TestDocumentProcessor extends SimpleDocumentProcessor {
    }
}