use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class URLRetrieveTest method testReceive.
protected void testReceive(String url) throws Exception {
assertNotNull(retrieveAdapter);
final IFileTransferListener listener = createFileTransferListener();
final IFileID fileID = createFileID(new URL(url));
retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
waitForDone(360000);
assertHasEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasMoreThanEventCount(dataEvents, IIncomingFileTransferReceiveDataEvent.class, 0);
assertDoneOK();
assertTrue(tmpFile.exists());
assertTrue(tmpFile.length() > 0);
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class URLRetrieveTestCancelConnectJob method testReceiveFile_cancelOnConnectEvent.
public void testReceiveFile_cancelOnConnectEvent() throws Exception {
if (!CANCEL_SUPPORTED_ON_CONNECT) {
trace("WARNING: Cancel not supported by this provider. testReceiveFile_cancelOnConnectEvent cannot be used");
return;
}
final IFileTransferListener listener = createFileTransferListener();
final FileTransferListenerWrapper lw = new FileTransferListenerWrapper(listener) {
protected void handleStartConnectEvent(IFileTransferConnectStartEvent event) {
assertNotNull(event.getFileID());
assertNotNull(event.getFileID().getFilename());
assertNull(socketInReadWrapper);
setDone(true);
event.cancel();
}
};
testReceive(URLRetrieveTest.HTTP_RETRIEVE, lw);
assertHasEvent(startConnectEvents, IFileTransferConnectStartEvent.class);
assertHasNoEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasNoEvent(dataEvents, IIncomingFileTransferReceiveDataEvent.class);
assertDoneCancelled();
assertNull(tmpFile);
socketEvents.validateNoSocketCreated();
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class URLRetrieveTestCancelConnectJob method testReceiveFile_cancelConnectJob.
// TODO: add test that cancel without connect job, when server does not
// respond
public void testReceiveFile_cancelConnectJob() throws Exception {
if (!CANCEL_SUPPORTED_ON_CONNECT) {
trace("WARNING: Cancel not supported by this provider. testReceiveFile_cancelConnectJob cannot be used");
return;
}
final Object[] doCancel = new Object[1];
final IFileTransferListener listener = createFileTransferListener();
final FileTransferListenerWrapper lw = new FileTransferListenerWrapper(listener) {
protected void handleStartConnectEvent(final IFileTransferConnectStartEvent event) {
assertNotNull(event.getFileID());
assertNotNull(event.getFileID().getFilename());
FileTransferJob connectJob = event.prepareConnectJob(null);
connectJob.addJobChangeListener(new JobChangeTraceListener(startTime) {
public void running(IJobChangeEvent jobEvent) {
super.running(jobEvent);
spawnCancelThread(doCancel, new ICancelable() {
public void cancel() {
assertNotNull(socketInReadWrapper);
assertTrue(socketInReadWrapper.inRead);
event.cancel();
}
});
}
});
event.connectUsingJob(connectJob);
}
};
final SimpleServer server = new SimpleServer(getName());
SimpleHttpServer simple = server.getSimpleHttpServer();
simple.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
trace("Not responding to request " + request.getRequestLine());
return stalledInRequestHandler(doCancel);
}
});
try {
// path does not matter as server does not respond.
testReceive(server.getServerURL() + "/foo", lw);
assertHasEvent(startConnectEvents, IFileTransferConnectStartEvent.class);
assertHasNoEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasNoEvent(dataEvents, IIncomingFileTransferReceiveDataEvent.class);
IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
assertTrue(doneEvent.getException().toString(), doneEvent.getException() instanceof UserCancelledException);
assertTrue(doneEvent.getSource().isDone());
assertSame(doneEvent.getException(), doneEvent.getSource().getException());
assertNull(tmpFile);
assertFalse(socketInReadWrapper.inRead);
socketEvents.validateOneSocketCreatedAndClosed();
} finally {
server.shutdown();
}
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class URLRetrieveTestCancelConnectJob method testReceiveFile_cancelTransferJob.
public void testReceiveFile_cancelTransferJob() throws Exception {
if (!CANCEL_SUPPORTED_ON_CONNECT) {
trace("WARNING: Cancel not supported by this provider. testReceiveFile_cancelTransferJob cannot be used");
return;
}
final Object[] doCancel = new Object[1];
final IFileTransferListener listener = createFileTransferListener();
final FileTransferListenerWrapper lw = new FileTransferListenerWrapper(listener) {
protected void handleStartConnectEvent(final IFileTransferConnectStartEvent event) {
assertNotNull(event.getFileID());
assertNotNull(event.getFileID().getFilename());
FileTransferJob connectJob = event.prepareConnectJob(null);
connectJob.addJobChangeListener(new JobChangeTraceListener(startTime));
event.connectUsingJob(connectJob);
}
protected void handleStartEvent(final IIncomingFileTransferReceiveStartEvent event) {
spawnCancelThread(doCancel, new ICancelable() {
public void cancel() {
waitForSocketInRead();
assertNotNull(socketInReadWrapper);
assertTrue(socketInReadWrapper.inRead);
event.cancel();
}
});
try {
createTempFile();
event.receive(tmpFile);
} catch (IOException e) {
e.printStackTrace();
fail(e.toString());
}
}
};
final SimpleServer server = new SimpleServer(getName());
SimpleHttpServer simple = server.getSimpleHttpServer();
simple.setRequestHandler(new HttpRequestHandler() {
public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
trace("Responding to request but never provide full body" + request.getRequestLine());
ResponseWriter w = conn.getWriter();
writeLines(w, new String[] { "HTTP/1.0 200 OK", "Content-Length: 9", "Content-Type: text/plain; charset=UTF-8", "" });
w.flush();
synchronized (doCancel) {
doCancel[0] = Boolean.TRUE;
}
conn.setKeepAlive(true);
//
return stalledInRequestHandler(doCancel);
}
});
try {
// path does not matter as server does not respond.
testReceive(server.getServerURL() + "/foo", lw);
assertHasEvent(startConnectEvents, IFileTransferConnectStartEvent.class);
assertHasEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertDoneCancelled();
assertNotNull(tmpFile);
assertTrue(tmpFile.exists());
assertEquals(0, tmpFile.length());
assertFalse(socketInReadWrapper.inRead);
socketEvents.validateOneSocketCreatedAndClosed();
} finally {
server.shutdown();
}
}
use of org.eclipse.ecf.filetransfer.IFileTransferListener in project ecf by eclipse.
the class GetRemoteFileNameTest method testReceive.
protected void testReceive(String url) throws Exception {
assertNotNull(retrieveAdapter);
final IFileTransferListener listener = createFileTransferListener();
final IFileID fileID = createFileID(new URL(url));
done = false;
retrieveAdapter.sendRetrieveRequest(fileID, listener, null);
synchronized (lock) {
try {
lock.wait(7000);
} catch (InterruptedException e) {
}
}
if (!done)
fail();
System.out.println("remote file name=" + incomingFileTransfer.getRemoteFileName());
waitForDone(10000);
assertHasEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
assertHasMoreThanEventCount(dataEvents, IIncomingFileTransferReceiveDataEvent.class, 0);
assertDoneOK();
assertTrue(tmpFile.exists());
assertTrue(tmpFile.length() > 0);
}
Aggregations