Search in sources :

Example 1 with PageConfig

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);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Response(jakarta.ws.rs.core.Response) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Configuration(org.opengrok.indexer.configuration.Configuration) PageConfig(org.opengrok.web.PageConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 Response (jakarta.ws.rs.core.Response)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1 Configuration (org.opengrok.indexer.configuration.Configuration)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)1 PageConfig (org.opengrok.web.PageConfig)1