aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliClientTest.java
blob: bfbb3f361854b10740c3eacb82ed83c1aa14d330 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.feed.client.impl;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author jonmv
 */
class CliClientTest {

    @Test
    void testDummyStream() throws IOException {
        AtomicInteger count = new AtomicInteger(3);
        InputStream in = CliClient.createDummyInputStream(4, new Random(0), () -> count.decrementAndGet() >= 0);
        byte[] buffer = new byte[1 << 20];
        int offset = 0, read;
        while ((read = in.read(buffer, offset, buffer.length - offset)) >= 0) offset += read;
        assertEquals("{ \"put\": \"id:test:test::ssxvnjhp\", \"fields\": { \"test\": \"dqdx\" } }\n" +
                     "{ \"put\": \"id:test:test::vcrastvy\", \"fields\": { \"test\": \"bcwv\" } }\n" +
                     "{ \"put\": \"id:test:test::mgnykrxv\", \"fields\": { \"test\": \"zxkg\" } }\n",
                     new String(buffer, 0, offset, StandardCharsets.UTF_8));
    }

}