Search in sources :

Example 1 with EventType

use of org.sonatype.aether.transfer.TransferEvent.EventType in project sonatype-aether by sonatype.

the class TransferEventTester method checkEvents.

private static void checkEvents(Queue<TransferEvent> events, long expectedBytes) {
    TransferEvent currentEvent = events.poll();
    String msg = "initiate event is missing";
    assertNotNull(msg, currentEvent);
    assertEquals(msg, INITIATED, currentEvent.getType());
    checkProperties(currentEvent);
    TransferResource expectedResource = currentEvent.getResource();
    currentEvent = events.poll();
    msg = "start event is missing";
    assertNotNull(msg, currentEvent);
    assertEquals(msg, TransferEvent.EventType.STARTED, currentEvent.getType());
    assertEquals("bad content length", expectedBytes, currentEvent.getResource().getContentLength());
    checkProperties(currentEvent);
    assertResourceEquals(expectedResource, currentEvent.getResource());
    EventType progressed = TransferEvent.EventType.PROGRESSED;
    EventType succeeded = TransferEvent.EventType.SUCCEEDED;
    TransferEvent succeedEvent = null;
    int dataLength = 0;
    long transferredBytes = 0;
    while ((currentEvent = events.poll()) != null) {
        EventType currentType = currentEvent.getType();
        assertResourceEquals(expectedResource, currentEvent.getResource());
        if (succeeded.equals(currentType)) {
            succeedEvent = currentEvent;
            checkProperties(currentEvent);
            break;
        } else {
            assertTrue("event is not 'succeeded' and not 'progressed'", progressed.equals(currentType));
            assertTrue("wrong order of progressed events, transferredSize got smaller, last = " + transferredBytes + ", current = " + currentEvent.getTransferredBytes(), currentEvent.getTransferredBytes() >= transferredBytes);
            assertEquals("bad content length", expectedBytes, currentEvent.getResource().getContentLength());
            transferredBytes = currentEvent.getTransferredBytes();
            dataLength += currentEvent.getDataBuffer().remaining();
            checkProperties(currentEvent);
        }
    }
    // all events consumed
    assertEquals("too many events left: " + events.toString(), 0, events.size());
    // test transferred size
    assertEquals("progress events transferred bytes don't match: data length does not add up", expectedBytes, dataLength);
    assertEquals("succeed event transferred bytes don't match", expectedBytes, succeedEvent.getTransferredBytes());
}
Also used : EventType(org.sonatype.aether.transfer.TransferEvent.EventType) TransferResource(org.sonatype.aether.transfer.TransferResource) TransferEvent(org.sonatype.aether.transfer.TransferEvent)

Aggregations

TransferEvent (org.sonatype.aether.transfer.TransferEvent)1 EventType (org.sonatype.aether.transfer.TransferEvent.EventType)1 TransferResource (org.sonatype.aether.transfer.TransferResource)1