Search in sources :

Example 6 with TransferEvent

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

the class TransferEventTester method checkFailedEvents.

private static void checkFailedEvents(Queue<TransferEvent> events, Class<? extends Throwable> expectedError) {
    if (expectedError == null) {
        expectedError = Throwable.class;
    }
    TransferEvent currentEvent = events.poll();
    String msg = "initiate event is missing";
    assertNotNull(msg, currentEvent);
    assertEquals(msg, INITIATED, currentEvent.getType());
    checkProperties(currentEvent);
    currentEvent = events.poll();
    msg = "fail event is missing";
    assertNotNull(msg, currentEvent);
    assertEquals(msg, TransferEvent.EventType.FAILED, currentEvent.getType());
    checkProperties(currentEvent);
    assertNotNull("exception is missing for fail event", currentEvent.getException());
    Exception exception = currentEvent.getException();
    assertTrue("exception is of wrong type, should be instance of " + expectedError + " but was " + exception.getClass(), expectedError.isAssignableFrom(exception.getClass()));
    // all events consumed
    assertEquals("too many events left: " + events.toString(), 0, events.size());
}
Also used : TransferEvent(org.sonatype.aether.transfer.TransferEvent) IOException(java.io.IOException) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException)

Example 7 with TransferEvent

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

the class TransferEventTester method testSuccessfulTransferEvents.

/**
     * Test the order of events and their properties for the successful up- and download of artifact and metadata.
     */
public static void testSuccessfulTransferEvents(RepositoryConnectorFactory factory, TestRepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException, IOException {
    RecordingTransferListener listener = new RecordingTransferListener(session.getTransferListener());
    session.setTransferListener(listener);
    RepositoryConnector connector = factory.newInstance(session, repository);
    byte[] pattern = "tmpFile".getBytes();
    File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
    long expectedBytes = tmpFile.length();
    Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, tmpFile);
    Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
    Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, tmpFile);
    Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
    connector.put(artUps, null);
    LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
    checkEvents(events, expectedBytes);
    listener.clear();
    connector.get(artDowns, null);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkEvents(events, expectedBytes);
    listener.clear();
    connector.put(null, metaUps);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkEvents(events, expectedBytes);
    listener.clear();
    connector.get(null, metaDowns);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkEvents(events, expectedBytes);
    connector.close();
    session.setTransferListener(null);
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) TransferEvent(org.sonatype.aether.transfer.TransferEvent) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RecordingTransferListener(org.sonatype.aether.test.impl.RecordingTransferListener) LinkedList(java.util.LinkedList) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File)

Example 8 with TransferEvent

use of org.sonatype.aether.transfer.TransferEvent 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)

Example 9 with TransferEvent

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

the class CompletionHandler method fireTransferStarted.

void fireTransferStarted() throws TransferCancelledException {
    final TransferEvent transferEvent = new AsyncTransferEvent() {

        public EventType getType() {
            return TransferEvent.EventType.STARTED;
        }

        public long getTransferredBytes() {
            return 0;
        }
    };
    for (Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); ) {
        final TransferListener listener = iter.next();
        listener.transferStarted(transferEvent);
    }
}
Also used : TransferListener(org.sonatype.aether.transfer.TransferListener) TransferEvent(org.sonatype.aether.transfer.TransferEvent)

Aggregations

TransferEvent (org.sonatype.aether.transfer.TransferEvent)9 TransferListener (org.sonatype.aether.transfer.TransferListener)4 File (java.io.File)3 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)3 RecordingTransferListener (org.sonatype.aether.test.impl.RecordingTransferListener)3 LinkedList (java.util.LinkedList)2 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)2 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)2 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)2 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 Artifact (org.sonatype.aether.artifact.Artifact)1 NoRepositoryConnectorException (org.sonatype.aether.transfer.NoRepositoryConnectorException)1 EventType (org.sonatype.aether.transfer.TransferEvent.EventType)1 TransferResource (org.sonatype.aether.transfer.TransferResource)1