use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.
the class CMRHTTPTests method testMdlHTTPTimeout.
@Test
public void testMdlHTTPTimeout() throws IOException {
String moduleA = "com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a";
// Clean up any cached version
File carFileInCache = getModuleArchive(moduleA, "6.6.6", cacheDir);
if (carFileInCache.exists())
carFileInCache.delete();
// Compile the first module in its own repo
File repo = makeRepo();
Boolean result = getCompilerTask(Arrays.asList("-out", repo.getPath()), "modules/depend/a/module.ceylon", "modules/depend/a/package.ceylon", "modules/depend/a/A.ceylon").call();
Assert.assertEquals(Boolean.TRUE, result);
File carFile = getModuleArchive(moduleA, "6.6.6", repo.getPath());
assertTrue(carFile.exists());
final int port = allocPortForTest();
final String repoAURL = getRepoUrl(port);
String[] files = new String[] { "modules/depend/b/module.ceylon", "modules/depend/b/package.ceylon", "modules/depend/b/a.ceylon", "modules/depend/b/B.ceylon" };
List<String> options = Arrays.asList("-out", destDir, "-rep", repoAURL, "-verbose:cmr", "-cp", getClassPathAsPath(), "-timeout", "1");
// now serve the first repo over HTTP
HttpServer server = startServer(port, repo, false, null, TimeoutIn.GetMiddle);
try {
// then try to compile only one module (the other being loaded from its car)
assertErrors(files, options, null, new CompilerError(24, "cannot find module artifact com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a-6.6.6.car\n" + " due to connection error: java.net.SocketTimeoutException: Timed out reading com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a-6.6.6.car from " + repoAURL + "\n" + " \t- dependency tree: com.redhat.ceylon.compiler.java.test.cmr.modules.depend.b/6.6.6 -> com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a/6.6.6"));
} finally {
server.stop(1);
}
if (carFileInCache.exists())
carFileInCache.delete();
server = startServer(port, repo, false, null, TimeoutIn.GetInitial);
try {
// then try to compile only one module (the other being loaded from its car)
assertErrors(files, options, null, new CompilerError(24, "cannot find module artifact com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a-6.6.6.car\n" + " due to connection error: java.net.SocketTimeoutException: Timed out during connection to " + repoAURL + "/com/redhat/ceylon/compiler/java/test/cmr/modules/depend/a/6.6.6/com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a-6.6.6.car\n" + " \t- dependency tree: com.redhat.ceylon.compiler.java.test.cmr.modules.depend.b/6.6.6 -> com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a/6.6.6"));
} finally {
server.stop(1);
}
if (carFileInCache.exists())
carFileInCache.delete();
server = startServer(port, repo, false, null, TimeoutIn.Head);
try {
// then try to compile only one module (the other being loaded from its car)
assertErrors(files, options, null, new CompilerError(24, "cannot find module artifact com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a-6.6.6(.car|.jar)\n" + " \t- dependency tree: com.redhat.ceylon.compiler.java.test.cmr.modules.depend.b/6.6.6 -> com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a/6.6.6"));
} finally {
server.stop(1);
}
// now with put
server = startServer(port, repo, true, null, TimeoutIn.PutInitial);
try {
// then try to compile our module by outputting to HTTP
assertErrors("modules/single/module", Arrays.asList("-out", repoAURL, "-verbose:cmr", "-timeout", "1"), null, new CompilerError(-1, "Failed to write module to repository: java.net.SocketTimeoutException: Timed out writing to " + repoAURL + "/com/redhat/ceylon/compiler/java/test/cmr/modules/single/6.6.6/com.redhat.ceylon.compiler.java.test.cmr.modules.single-6.6.6.src"));
} finally {
server.stop(1);
}
// now with put
server = startServer(port, repo, true, null, TimeoutIn.PutMiddle);
try {
// then try to compile our module by outputting to HTTP
assertErrors("modules/single/module", Arrays.asList("-out", repoAURL, "-verbose:cmr", "-timeout", "1"), null, new CompilerError(-1, "Failed to write module to repository: java.net.SocketTimeoutException: Timed out writing to " + repoAURL + "/com/redhat/ceylon/compiler/java/test/cmr/modules/single/6.6.6/com.redhat.ceylon.compiler.java.test.cmr.modules.single-6.6.6.src"));
} finally {
server.stop(1);
}
}
use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.
the class CMRHTTPTests method testMdlHTTPOutputRepo.
private void testMdlHTTPOutputRepo(boolean herd, int requests) throws IOException {
RequestCounter rq = new RequestCounter();
// Compile the module in its own repo
File repo = makeRepo();
final int port = allocPortForTest();
final String repoAURL = getRepoUrl(port);
// now serve the first repo over HTTP
HttpServer server = startServer(port, repo, herd, rq);
try {
// then try to compile our module by outputting to HTTP
Boolean result = getCompilerTask(Arrays.asList("-out", repoAURL, "-verbose:cmr"), "modules/single/module.ceylon").call();
Assert.assertEquals(Boolean.TRUE, result);
} finally {
server.stop(1);
}
File carFile = getModuleArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.single", "6.6.6", repo.getPath());
assertTrue(carFile.exists());
JarFile car = new JarFile(carFile);
// make sure it's not empty
ZipEntry moduleClass = car.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/single/$module_.class");
assertNotNull(moduleClass);
car.close();
File srcFile = getSourceArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.single", "6.6.6", repo.getPath());
assertTrue(srcFile.exists());
rq.check(requests);
}
use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.
the class CMRHTTPTests method startServer.
private HttpServer startServer(int port, File repo, boolean herd, RequestCounter rq, ExpectedError error) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(port), 1);
server.createContext("/repo", new RepoFileHandler(repo.getPath(), herd, rq, error));
// make sure we serve at least two concurrent connections, as each one might take a few ms to close
ThreadPoolExecutor tpool = (ThreadPoolExecutor) Executors.newFixedThreadPool(2);
server.setExecutor(tpool);
server.start();
return server;
}
use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.
the class CMRHTTPTests method testMdlHTTPMixedCompilation.
private void testMdlHTTPMixedCompilation(boolean herd, int requests) throws IOException {
RequestCounter rq = new RequestCounter();
// Compile the first module in its own repo
File repo = makeRepo();
final int port = allocPortForTest();
final String repoAURL = getRepoUrl(port);
// now serve the first repo over HTTP
HttpServer server = startServer(port, repo, herd, rq);
try {
// then try to compile our module by outputting to HTTP
Boolean result = getCompilerTask(Arrays.asList("-out", repoAURL, "-verbose:cmr"), "modules/mixed/JavaClass.java").call();
Assert.assertEquals(Boolean.TRUE, result);
result = getCompilerTask(Arrays.asList("-out", repoAURL, "-verbose:cmr"), "modules/mixed/CeylonClass.ceylon").call();
Assert.assertEquals(Boolean.TRUE, result);
} finally {
server.stop(1);
}
File carFile = getModuleArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.mixed", "6.6.6", repo.getPath());
assertTrue(carFile.exists());
JarFile car = new JarFile(carFile);
// make sure it's not empty
ZipEntry entry = car.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/mixed/$module_.class");
assertNotNull(entry);
entry = car.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/mixed/CeylonClass.class");
assertNotNull(entry);
entry = car.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/mixed/JavaClass.class");
assertNotNull(entry);
car.close();
File srcFile = getSourceArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.mixed", "6.6.6", repo.getPath());
assertTrue(srcFile.exists());
JarFile src = new JarFile(srcFile);
// make sure it's not empty
entry = src.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/mixed/module.ceylon");
assertNotNull(entry);
entry = src.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/mixed/CeylonClass.ceylon");
assertNotNull(entry);
entry = src.getEntry("com/redhat/ceylon/compiler/java/test/cmr/modules/mixed/JavaClass.java");
assertNotNull(entry);
src.close();
rq.check(requests);
}
use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.
the class CMRHTTPTests method testMdlHTTPForbidden.
@Test
public void testMdlHTTPForbidden() throws IOException {
File repo = makeRepo();
final int port = allocPortForTest();
final String repoAURL = getRepoUrl(port);
HttpServer server = startServer(port, repo, true, null, HttpError.FORBIDDEN);
try {
// then try to compile our module by outputting to HTTP
assertErrors("modules/single/module", Arrays.asList("-out", repoAURL), null, new CompilerError(-1, "Failed to write module to repository: authentication failed on repository " + repoAURL));
} finally {
server.stop(1);
}
}
Aggregations