use of org.opengrok.web.PageConfig in project OpenGrok by OpenGrok.
the class ConfigurationControllerTest method testConfigValueSetVsThread.
@Test
void testConfigValueSetVsThread() throws InterruptedException {
int origValue = env.getHitsPerPage();
final int[] threadValue = new int[1];
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(1);
Thread thread = new Thread(() -> {
HttpServletRequest req = new DummyHttpServletRequest();
PageConfig pageConfig = PageConfig.get(req);
RuntimeEnvironment e = pageConfig.getEnv();
startLatch.countDown();
// Wait for hint of termination, save the value and exit.
try {
endLatch.await();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
threadValue[0] = e.getHitsPerPage();
});
thread.start();
startLatch.await();
// Set brand-new configuration.
int newValue = origValue + 42;
Configuration config = new Configuration();
config.setHitsPerPage(newValue);
String configStr = config.getXMLRepresentationAsString();
Response response = target("configuration").request().put(Entity.xml(configStr));
waitForTask(response);
// Unblock the thread.
endLatch.countDown();
thread.join();
// Check thread's view of the variable.
assertEquals(newValue, threadValue[0]);
// Revert the value back to the default.
env.setHitsPerPage(origValue);
}
Aggregations