Skip to content
Snippets Groups Projects
Commit c7e04386 authored by ik1g19's avatar ik1g19
Browse files

add test files

parent 1d351b77
No related branches found
No related tags found
No related merge requests found
package com.javacodegeeks.nio.large_file_transfer;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
public abstract class AbstractTest {
protected static final String SRC = "/tmp/input.tar.gz";
protected static final String TARGET = "/tmp/output";
protected static final long AWAIT_TEST_COMPLETE = 20000l;
protected File srcFile;
protected File targetFile;
@BeforeClass
public static void init() {
Thread.currentThread().getContextClassLoader().setDefaultAssertionStatus(true);
}
@AfterClass
public static void destroy() {
Thread.currentThread().getContextClassLoader().setDefaultAssertionStatus(false);
}
@Before
public void setUp() throws IOException {
this.srcFile = new File(SRC);
this.targetFile = new File(TARGET + "/" + this.srcFile.getName());
Files.deleteIfExists(this.targetFile.toPath());
}
protected final void compare() {
assertEquals("file did not copy completely", this.srcFile.length(), this.targetFile.length());
}
}
package com.javacodegeeks.nio.large_file_transfer.remote;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import org.junit.Test;
import com.javacodegeeks.nio.large_file_transfer.AbstractTest;
public class FileCopyTest extends AbstractTest {
private static final int PORT = 9999;
@Test
public void copyLargeFile() throws IOException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final FileReceiver receiver = new FileReceiver(PORT, new FileWriter(TARGET + "/" + super.srcFile.getName()), super.srcFile.length());
new Thread() {
public void run() {
try {
receiver.receive();
} catch (IOException e) {
} finally {
latch.countDown();
}
}
}.start();
final FileReader reader = new FileReader(new FileSender(PORT), SRC);
reader.read();
latch.await();
compare();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment