Search in sources :

Example 21 with RateMeasure

use of org.nustaq.kontraktor.util.RateMeasure in project kontraktor by RuedigerMoeller.

the class AsyncServerSocketTest method writeTest.

@Test
public void writeTest() throws IOException, InterruptedException {
    File f = new File("/tmp/data.test");
    int NUMINT = 10_000_000;
    if (!f.exists()) {
        FileOutputStream fout = new FileOutputStream(f);
        DataOutputStream dout = new DataOutputStream(fout);
        for (int i = 0; i < NUMINT; i++) {
            dout.writeInt(i);
        }
        fout.close();
    }
    System.out.println("file len " + f.length());
    TA ta = Actors.AsActor(TA.class);
    ta.serve3(8081).await();
    RateMeasure intFreq = new RateMeasure("int per sec");
    TCPObjectSocket sock = null;
    try {
        sock = new TCPObjectSocket("localhost", 8081);
        sock.writeObject(f);
        sock.flush();
        byte[] res = new byte[1024];
        int count = 0;
        int read;
        InputStream in = sock.getIn();
        DataInputStream din = new DataInputStream(in);
        while ((read = din.readInt()) >= 0) {
            Assert.assertTrue(read == count);
            count++;
            if (count == NUMINT)
                break;
            // if ( count % 10000 == 0 )
            // System.out.println("read int "+count);
            intFreq.count();
        }
        in.close();
        System.out.println("received " + count + " KB");
    } catch (Exception e) {
        e.printStackTrace();
    }
    ta.stop();
    Thread.sleep(1000);
}
Also used : RateMeasure(org.nustaq.kontraktor.util.RateMeasure) TCPObjectSocket(org.nustaq.net.TCPObjectSocket) AsyncFile(org.nustaq.kontraktor.asyncio.AsyncFile) Test(org.junit.Test)

Aggregations

RateMeasure (org.nustaq.kontraktor.util.RateMeasure)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 Test (org.junit.Test)20 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)13 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)13 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 Actors (org.nustaq.kontraktor.Actors)12 IntStream (java.util.stream.IntStream)10 Log (org.nustaq.kontraktor.util.Log)10 Assert (org.junit.Assert)9 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)9 Publisher (org.reactivestreams.Publisher)9 RxReactiveStreams (rx.RxReactiveStreams)9 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)8 ActorSystem (akka.actor.ActorSystem)7 ActorMaterializer (akka.stream.ActorMaterializer)7 ActorMaterializerSettings (akka.stream.ActorMaterializerSettings)7 Materializer (akka.stream.Materializer)7 PublisherSink (akka.stream.impl.PublisherSink)7