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