use of org.apache.catalina.core.StandardContext in project tomcat by apache.
the class TestHttpServlet method doTestHead.
private void doTestHead(Servlet servlet) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
Wrapper w = Tomcat.addServlet(ctx, "TestServlet", servlet);
// Not all need/use this but it is simpler to set it for all
w.setAsyncSupported(true);
ctx.addServletMappingDecoded("/test", "TestServlet");
tomcat.start();
Map<String, List<String>> getHeaders = new CaseInsensitiveKeyMap<>();
String path = "http://localhost:" + getPort() + "/test";
ByteChunk out = new ByteChunk();
int rc = getUrl(path, out, getHeaders);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
out.recycle();
Map<String, List<String>> headHeaders = new HashMap<>();
rc = headUrl(path, out, headHeaders);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
// Headers should be the same (apart from Date)
Assert.assertEquals(getHeaders.size(), headHeaders.size());
for (Map.Entry<String, List<String>> getHeader : getHeaders.entrySet()) {
String headerName = getHeader.getKey();
if ("date".equalsIgnoreCase(headerName)) {
continue;
}
Assert.assertTrue(headerName, headHeaders.containsKey(headerName));
List<String> getValues = getHeader.getValue();
List<String> headValues = headHeaders.get(headerName);
Assert.assertEquals(getValues.size(), headValues.size());
for (String value : getValues) {
Assert.assertTrue(headValues.contains(value));
}
}
tomcat.stop();
}
use of org.apache.catalina.core.StandardContext in project tomcat by apache.
the class TestPersistentManagerIntegration method testCreateSessionAndPassivate.
@Test
public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
ctx.setDistributable(true);
Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
ctx.addServletMappingDecoded("/dummy", "DummyServlet");
PersistentManager manager = new PersistentManager();
TesterStore store = new TesterStore();
manager.setStore(store);
manager.setMaxIdleBackup(0);
manager.setSessionActivityCheck(true);
ctx.setManager(manager);
ctx.addValve(new PersistentValve());
tomcat.start();
Assert.assertEquals("No active sessions", manager.getActiveSessions(), 0);
Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
String sessionId = getUrl("http://localhost:" + getPort() + "/dummy?no_create_session=false").toString();
Assert.assertNotNull("Session is stored", store.load(sessionId));
Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty());
}
use of org.apache.catalina.core.StandardContext in project tomcat by apache.
the class Benchmarks method doTestManagerBaseCreateSession.
private void doTestManagerBaseCreateSession(int threadCount, int iterCount) throws LifecycleException {
// Create a default session manager
StandardManager mgr = new StandardManager();
mgr.setPathname(null);
Host host = new StandardHost();
host.setName("unittest");
Context context = new StandardContext();
context.setPath("");
context.setParent(host);
mgr.setContext(context);
mgr.start();
mgr.generateSessionId();
while (mgr.sessionCreationTiming.size() < ManagerBase.TIMING_STATS_CACHE_SIZE) {
mgr.sessionCreationTiming.add(null);
}
while (mgr.sessionExpirationTiming.size() < ManagerBase.TIMING_STATS_CACHE_SIZE) {
mgr.sessionExpirationTiming.add(null);
}
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
threads[i] = new Thread(new TestThreadCreateSession(mgr, iterCount));
}
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
threads[i].start();
}
for (int i = 0; i < threadCount; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
long end = System.currentTimeMillis();
StringBuilder result = new StringBuilder();
result.append("Threads: ");
result.append(threadCount);
result.append(", Time(ms): ");
result.append(end - start);
System.out.println(result.toString());
}
use of org.apache.catalina.core.StandardContext in project tomcat by apache.
the class TestMapper method createContext.
private Context createContext(String name) {
Context context = new StandardContext();
context.setName(name);
return context;
}
use of org.apache.catalina.core.StandardContext in project tomcat by apache.
the class TestVirtualWebappLoader method testStartInternal.
@Test
public void testStartInternal() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp");
StandardContext ctx = (StandardContext) tomcat.addContext("", appDir.getAbsolutePath());
WebappLoader loader = new WebappLoader();
loader.setContext(ctx);
ctx.setLoader(loader);
ctx.setResources(new StandardRoot(ctx));
ctx.resourcesStart();
File f1 = new File("test/webapp-fragments/WEB-INF/lib");
ctx.getResources().createWebResourceSet(WebResourceRoot.ResourceSetType.POST, "/WEB-INF/lib", f1.getAbsolutePath(), null, "/");
loader.start();
String[] repos = loader.getLoaderRepositories();
Assert.assertEquals(4, repos.length);
loader.stop();
repos = loader.getLoaderRepositories();
Assert.assertEquals(0, repos.length);
// no leak
loader.start();
repos = loader.getLoaderRepositories();
Assert.assertEquals(4, repos.length);
// clear loader
ctx.setLoader(null);
// see tearDown()!
tomcat.start();
}
Aggregations