Search in sources :

Example 1 with Deserializer

use of com.carrotsearch.ant.tasks.junit4.events.Deserializer in project randomizedtesting by randomizedtesting.

the class LocalSlaveStreamHandler method pumpEvents.

/**
 * Pump events from event stream.
 */
void pumpEvents(InputStream eventStream) {
    try {
        Deserializer deserializer = new Deserializer(eventStream, refLoader);
        IEvent event = null;
        while ((event = deserializer.deserialize()) != null) {
            switch(event.getType()) {
                case APPEND_STDERR:
                case APPEND_STDOUT:
                    // Ignore these two on activity heartbeats. GH-117
                    break;
                default:
                    lastActivity = System.currentTimeMillis();
                    break;
            }
            try {
                switch(event.getType()) {
                    case QUIT:
                        eventBus.post(event);
                        return;
                    case IDLE:
                        eventBus.post(new SlaveIdle(stdinWriter));
                        break;
                    case BOOTSTRAP:
                        clientCharset = Charset.forName(((BootstrapEvent) event).getDefaultCharsetName());
                        stdinWriter = new OutputStreamWriter(stdin, clientCharset);
                        eventBus.post(event);
                        break;
                    case APPEND_STDERR:
                    case APPEND_STDOUT:
                        assert streamsBuffer.getFilePointer() == streamsBuffer.length();
                        final long bufferStart = streamsBuffer.getFilePointer();
                        IStreamEvent streamEvent = (IStreamEvent) event;
                        streamEvent.copyTo(streamsBufferWrapper);
                        final long bufferEnd = streamsBuffer.getFilePointer();
                        event = new OnDiskStreamEvent(event.getType(), streamsBuffer, bufferStart, bufferEnd);
                        eventBus.post(event);
                        break;
                    default:
                        eventBus.post(event);
                }
            } catch (Throwable t) {
                warnStream.println("Event bus dispatch error: " + t.toString());
                t.printStackTrace(warnStream);
            }
        }
        lastActivity = null;
    } catch (Throwable e) {
        if (!stopping) {
            warnStream.println("Event stream error: " + e.toString());
            e.printStackTrace(warnStream);
        }
    }
}
Also used : IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) IStreamEvent(com.carrotsearch.ant.tasks.junit4.events.IStreamEvent) Deserializer(com.carrotsearch.ant.tasks.junit4.events.Deserializer) BootstrapEvent(com.carrotsearch.ant.tasks.junit4.events.BootstrapEvent) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with Deserializer

use of com.carrotsearch.ant.tasks.junit4.events.Deserializer in project randomizedtesting by randomizedtesting.

the class TestJsonByteArrayRoundtrip method check.

private void check(byte[] bytes) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Serializer s = new Serializer(baos);
    s.serialize(new AppendStdErrEvent(bytes, 0, bytes.length));
    s.flush();
    s.close();
    Deserializer deserializer = new Deserializer(new ByteArrayInputStream(baos.toByteArray()), Thread.currentThread().getContextClassLoader());
    IEvent deserialize = deserializer.deserialize();
    Assert.assertTrue(deserialize instanceof AppendStdErrEvent);
    AppendStdErrEvent e = ((AppendStdErrEvent) deserialize);
    baos.reset();
    e.copyTo(baos);
    Assert.assertTrue("Exp: " + Arrays.toString(bytes) + "\n" + "was: " + Arrays.toString(baos.toByteArray()), Arrays.equals(bytes, baos.toByteArray()));
}
Also used : AppendStdErrEvent(com.carrotsearch.ant.tasks.junit4.events.AppendStdErrEvent) IEvent(com.carrotsearch.ant.tasks.junit4.events.IEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) Deserializer(com.carrotsearch.ant.tasks.junit4.events.Deserializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Serializer(com.carrotsearch.ant.tasks.junit4.events.Serializer)

Aggregations

Deserializer (com.carrotsearch.ant.tasks.junit4.events.Deserializer)2 IEvent (com.carrotsearch.ant.tasks.junit4.events.IEvent)2 AppendStdErrEvent (com.carrotsearch.ant.tasks.junit4.events.AppendStdErrEvent)1 BootstrapEvent (com.carrotsearch.ant.tasks.junit4.events.BootstrapEvent)1 IStreamEvent (com.carrotsearch.ant.tasks.junit4.events.IStreamEvent)1 Serializer (com.carrotsearch.ant.tasks.junit4.events.Serializer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1