Skip to content

Commit fd17fd1

Browse files
idodeclareVladimir Kotal
authored and
Vladimir Kotal
committed
Marshal random port through CONTAINER_PORT forced property
1 parent 298ce67 commit fd17fd1

14 files changed

+208
-59
lines changed

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/AnnotationControllerTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
/*
2121
* Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2223
*/
2324

2425
package org.opengrok.web.api.v1.controller;
2526

2627
import org.glassfish.jersey.server.ResourceConfig;
27-
import org.glassfish.jersey.test.JerseyTest;
2828
import org.junit.After;
2929
import org.junit.Before;
3030
import org.junit.Rule;
@@ -56,7 +56,7 @@
5656
import static org.junit.jupiter.api.Assertions.assertTrue;
5757

5858
@ConditionalRun(RepositoryInstalled.GitInstalled.class)
59-
public class AnnotationControllerTest extends JerseyTest {
59+
public class AnnotationControllerTest extends OGKJerseyTest {
6060

6161
@Rule
6262
public ConditionalRunRule rule = new ConditionalRunRule();
@@ -71,6 +71,7 @@ protected Application configure() {
7171
}
7272

7373
@Before
74+
@Override
7475
public void setUp() throws Exception {
7576
super.setUp();
7677
repository = new TestRepository();
@@ -92,6 +93,7 @@ public void setUp() throws Exception {
9293
}
9394

9495
@After
96+
@Override
9597
public void tearDown() throws Exception {
9698
super.tearDown();
9799

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/ConcurrentConfigurationControllerTest.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
124
package org.opengrok.web.api.v1.controller;
225

326
import java.nio.file.Paths;
@@ -17,7 +40,6 @@
1740
import org.apache.commons.io.FileUtils;
1841
import org.glassfish.jersey.internal.inject.AbstractBinder;
1942
import org.glassfish.jersey.server.ResourceConfig;
20-
import org.glassfish.jersey.test.JerseyTest;
2143
import org.junit.After;
2244
import org.junit.Assert;
2345
import org.junit.Before;
@@ -36,7 +58,7 @@
3658
import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService;
3759

3860
@ConditionalRun(RepositoryInstalled.GitInstalled.class)
39-
public class ConcurrentConfigurationControllerTest extends JerseyTest {
61+
public class ConcurrentConfigurationControllerTest extends OGKJerseyTest {
4062

4163
private static final int PROJECTS_COUNT = 20;
4264
private static final int THREAD_COUNT = Math.max(30, Runtime.getRuntime().availableProcessors() * 2);
@@ -69,6 +91,7 @@ protected void configure() {
6991
}
7092

7193
@Before
94+
@Override
7295
public void setUp() throws Exception {
7396
super.setUp();
7497
origSourceRootPath = env.getSourceRootPath();
@@ -112,6 +135,7 @@ public void setUp() throws Exception {
112135
}
113136

114137
@After
138+
@Override
115139
public void tearDown() throws Exception {
116140
super.tearDown();
117141
repository.destroy();

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/ConfigurationControllerTest.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,32 @@
1919

2020
/*
2121
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.web.api.v1.controller;
2425

2526
import static org.junit.Assert.assertEquals;
2627
import static org.mockito.Mockito.reset;
2728
import static org.mockito.Mockito.verify;
2829

29-
import java.io.IOException;
30-
import java.nio.file.Paths;
31-
import java.util.ArrayList;
32-
import java.util.List;
33-
import java.util.Map;
34-
import java.util.TreeMap;
3530
import java.util.concurrent.CountDownLatch;
3631
import javax.servlet.http.HttpServletRequest;
3732
import javax.ws.rs.client.Entity;
3833
import javax.ws.rs.core.Application;
3934
import javax.ws.rs.core.Response;
40-
import org.apache.commons.io.FileUtils;
4135
import org.glassfish.jersey.internal.inject.AbstractBinder;
4236
import org.glassfish.jersey.server.ResourceConfig;
43-
import org.glassfish.jersey.test.JerseyTest;
4437
import org.junit.Assert;
45-
import org.junit.Rule;
4638
import org.junit.Test;
4739
import org.mockito.Mock;
4840
import org.mockito.MockitoAnnotations;
49-
import org.opengrok.indexer.condition.ConditionalRun;
50-
import org.opengrok.indexer.condition.ConditionalRunRule;
51-
import org.opengrok.indexer.condition.RepositoryInstalled;
5241
import org.opengrok.indexer.configuration.Configuration;
53-
import org.opengrok.indexer.configuration.Project;
5442
import org.opengrok.indexer.configuration.RuntimeEnvironment;
55-
import org.opengrok.indexer.history.HistoryGuru;
56-
import org.opengrok.indexer.history.RepositoryInfo;
57-
import org.opengrok.indexer.util.TestRepository;
5843
import org.opengrok.indexer.web.DummyHttpServletRequest;
5944
import org.opengrok.indexer.web.PageConfig;
6045
import org.opengrok.web.api.v1.suggester.provider.service.SuggesterService;
6146

62-
public class ConfigurationControllerTest extends JerseyTest {
47+
public class ConfigurationControllerTest extends OGKJerseyTest {
6348

6449
private RuntimeEnvironment env = RuntimeEnvironment.getInstance();
6550

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/FileControllerTest.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
124
package org.opengrok.web.api.v1.controller;
225

326
import org.glassfish.jersey.server.ResourceConfig;
4-
import org.glassfish.jersey.test.JerseyTest;
527
import org.junit.After;
628
import org.junit.Before;
729
import org.junit.Test;
@@ -21,7 +43,7 @@
2143

2244
import static org.junit.Assert.assertEquals;
2345

24-
public class FileControllerTest extends JerseyTest {
46+
public class FileControllerTest extends OGKJerseyTest {
2547

2648
private RuntimeEnvironment env = RuntimeEnvironment.getInstance();
2749

@@ -33,6 +55,7 @@ protected Application configure() {
3355
}
3456

3557
@Before
58+
@Override
3659
public void setUp() throws Exception {
3760
super.setUp();
3861
repository = new TestRepository();
@@ -55,6 +78,7 @@ public void setUp() throws Exception {
5578
}
5679

5780
@After
81+
@Override
5882
public void tearDown() throws Exception {
5983
super.tearDown();
6084

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/HistoryControllerTest.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
124
package org.opengrok.web.api.v1.controller;
225

326
import org.glassfish.jersey.server.ResourceConfig;
4-
import org.glassfish.jersey.test.JerseyTest;
527
import org.junit.After;
628
import org.junit.Before;
729
import org.junit.Rule;
@@ -33,7 +55,7 @@
3355
import static org.opengrok.web.api.v1.controller.HistoryController.getHistoryDTO;
3456

3557
@ConditionalRun(RepositoryInstalled.GitInstalled.class)
36-
public class HistoryControllerTest extends JerseyTest {
58+
public class HistoryControllerTest extends OGKJerseyTest {
3759

3860
private RuntimeEnvironment env = RuntimeEnvironment.getInstance();
3961

@@ -48,6 +70,7 @@ protected Application configure() {
4870
}
4971

5072
@Before
73+
@Override
5174
public void setUp() throws Exception {
5275
super.setUp();
5376
repository = new TestRepository();
@@ -69,6 +92,7 @@ public void setUp() throws Exception {
6992
}
7093

7194
@After
95+
@Override
7296
public void tearDown() throws Exception {
7397
super.tearDown();
7498

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/MessagesControllerTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.web.api.v1.controller;
2425

@@ -30,7 +31,6 @@
3031
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
3132
import org.glassfish.jersey.server.ResourceConfig;
3233
import org.glassfish.jersey.test.DeploymentContext;
33-
import org.glassfish.jersey.test.JerseyTest;
3434
import org.glassfish.jersey.test.spi.TestContainer;
3535
import org.glassfish.jersey.test.spi.TestContainerException;
3636
import org.glassfish.jersey.test.spi.TestContainerFactory;
@@ -57,7 +57,6 @@
5757
import java.util.Collections;
5858
import java.util.HashSet;
5959
import java.util.List;
60-
import java.util.Locale;
6160
import java.util.Set;
6261

6362
import static org.hamcrest.MatcherAssert.assertThat;
@@ -66,7 +65,7 @@
6665
import static org.junit.Assert.assertFalse;
6766
import static org.junit.Assert.assertTrue;
6867

69-
public class MessagesControllerTest extends JerseyTest {
68+
public class MessagesControllerTest extends OGKJerseyTest {
7069

7170
private static final GenericType<List<AcceptedMessageModel>> messagesType =
7271
new GenericType<List<AcceptedMessageModel>>() {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2020, Chris Fraire <[email protected]>.
22+
*/
23+
24+
package org.opengrok.web.api.v1.controller;
25+
26+
import org.glassfish.jersey.test.JerseyTest;
27+
import org.glassfish.jersey.test.TestProperties;
28+
import org.junit.Before;
29+
30+
import java.util.Random;
31+
32+
/**
33+
* Represents a subclass of {@link JerseyTest} customized for OpenGrok.
34+
*/
35+
public abstract class OGKJerseyTest extends JerseyTest {
36+
37+
private static final int BASE_DYNAMIC_OR_PRIVATE_PORT = 49152;
38+
39+
/** Random.nextInt() will be at most one less than this -- but OK */
40+
private static final int DYNAMIC_OR_PRIVATE_PORT_RANGE = 16383;
41+
42+
private final Random rand = new Random();
43+
44+
/**
45+
* Marshal a random high port through {@link TestProperties#CONTAINER_PORT}
46+
* for use by {@link #getPort()}.
47+
*/
48+
@Before
49+
public void setUp() throws Exception {
50+
int jerseyPort = BASE_DYNAMIC_OR_PRIVATE_PORT +
51+
rand.nextInt(DYNAMIC_OR_PRIVATE_PORT_RANGE);
52+
forceSet(TestProperties.CONTAINER_PORT, String.valueOf(jerseyPort));
53+
54+
super.setUp();
55+
}
56+
}

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/ProjectsControllerTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919

2020
/*
2121
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2019-2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.web.api.v1.controller;
2525

2626
import org.glassfish.jersey.internal.inject.AbstractBinder;
2727
import org.glassfish.jersey.server.ResourceConfig;
28-
import org.glassfish.jersey.test.JerseyTest;
2928
import org.junit.After;
3029
import org.junit.Before;
3130
import org.junit.Rule;
@@ -76,7 +75,7 @@
7675
@ConditionalRun(RepositoryInstalled.MercurialInstalled.class)
7776
@ConditionalRun(RepositoryInstalled.GitInstalled.class)
7877
@ConditionalRun(RepositoryInstalled.SubversionInstalled.class)
79-
public class ProjectsControllerTest extends JerseyTest {
78+
public class ProjectsControllerTest extends OGKJerseyTest {
8079

8180
private RuntimeEnvironment env = RuntimeEnvironment.getInstance();
8281

@@ -101,6 +100,7 @@ protected void configure() {
101100
}
102101

103102
@Before
103+
@Override
104104
public void setUp() throws Exception {
105105
super.setUp();
106106
repository = new TestRepository();
@@ -115,6 +115,7 @@ public void setUp() throws Exception {
115115
}
116116

117117
@After
118+
@Override
118119
public void tearDown() throws Exception {
119120
super.tearDown();
120121
// This should match Configuration constructor.

0 commit comments

Comments
 (0)