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);
}
Aggregations