How to use ExternalResource class of org.junit.rules package

Best junit code snippet using org.junit.rules.ExternalResource

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.junit;
2
3import java.lang.annotation.ElementType;
4import java.lang.annotation.Retention;
5import java.lang.annotation.RetentionPolicy;
6import java.lang.annotation.Target;
7
8/**
9 * Annotates static fields that reference rules or methods that return them. A field must be public,
10 * static, and a subtype of {@link org.junit.rules.TestRule}.  A method must be public static, and return
11 * a subtype of {@link org.junit.rules.TestRule}.
12 * <p>
13 * The {@link org.junit.runners.model.Statement} passed
14 * to the {@link org.junit.rules.TestRule} will run any {@link BeforeClass} methods,
15 * then the entire body of the test class (all contained methods, if it is
16 * a standard JUnit test class, or all contained classes, if it is a
17 * {@link org.junit.runners.Suite}), and finally any {@link AfterClass} methods.
18 * <p>
19 * The statement passed to the {@link org.junit.rules.TestRule} will never throw an exception,
20 * and throwing an exception from the {@link org.junit.rules.TestRule} will result in undefined
21 * behavior.  This means that some {@link org.junit.rules.TestRule}s, such as
22 * {@link org.junit.rules.ErrorCollector},
23 * {@link org.junit.rules.ExpectedException},
24 * and {@link org.junit.rules.Timeout},
25 * have undefined behavior when used as {@link ClassRule}s.
26 * <p>
27 * If there are multiple
28 * annotated {@link ClassRule}s on a class, they will be applied in an order
29 * that depends on your JVM's implementation of the reflection API, which is
30 * undefined, in general. However, Rules defined by fields will always be applied
31 * before Rules defined by methods.
32 * <p>
33 * For example, here is a test suite that connects to a server once before
34 * all the test classes run, and disconnects after they are finished:
35 * <pre>
36 * &#064;RunWith(Suite.class)
37 * &#064;SuiteClasses({A.class, B.class, C.class})
38 * public class UsesExternalResource {
39 *     public static Server myServer= new Server();
40 *
41 *     &#064;ClassRule
42 *     public static ExternalResource resource= new ExternalResource() {
43 *       &#064;Override
44 *       protected void before() throws Throwable {
45 *          myServer.connect();
46 *      }
47 *
48 *      &#064;Override
49 *      protected void after() {
50 * 	        myServer.disconnect();
51 *      }
52 *   };
53 * }
54 * </pre>
55 * <p>
56 * and the same using a method
57 * <pre>
58 * &#064;RunWith(Suite.class)
59 * &#064;SuiteClasses({A.class, B.class, C.class})
60 * public class UsesExternalResource {
61 *     public static Server myServer= new Server();
62 *
63 *     &#064;ClassRule
64 *     public static ExternalResource getResource() {
65 *         return new ExternalResource() {
66 *             &#064;Override
67 *             protected void before() throws Throwable {
68 *                 myServer.connect();
69 *             }
70 *
71 *             &#064;Override
72 *             protected void after() {
73 *                 myServer.disconnect();
74 *             }
75 *         };
76 *     }
77 * }
78 * </pre>
79 * <p>
80 * For more information and more examples, see {@link org.junit.rules.TestRule}.
81 *
82 * @since 4.9
83 */
84@Retention(RetentionPolicy.RUNTIME)
85@Target({ElementType.FIELD, ElementType.METHOD})
86public @interface ClassRule {
87}
88
Full Screen
copy
1package com.sourcegraph.lsp.benchmarks;
2
3import com.google.common.collect.Maps;
4import com.sourcegraph.lsp.Harness;
5import com.sourcegraph.lsp.domain.result.TextDocumentReferencesResult;
6import com.sourcegraph.lsp.domain.result.TextDocumentXDefinitionResult;
7import com.sourcegraph.lsp.domain.result.WorkspaceSymbolResult;
8import com.sourcegraph.lsp.domain.result.WorkspaceXReferencesResult;
9import com.sourcegraph.lsp.domain.structures.*;
10import org.junit.Ignore;
11import org.junit.FixMethodOrder;
12import org.junit.Test;
13import org.junit.runners.MethodSorters;
14import org.slf4j.Logger;
15import org.slf4j.LoggerFactory;
16
17import javax.lang.model.element.ElementKind;
18
19/**
20 * Created by alexsaveliev on 15.02.2017.
21 */
22@FixMethodOrder(MethodSorters.NAME_ASCENDING)
23public class Dropwizard extends BenchmarkTestBase {
24
25    private static final Logger LOG = LoggerFactory.getLogger(Dropwizard.class);
26
27    private static String REPO = "dropwizard";
28
29    /**
30     * IMPORTANT: Test names define tests execution order
31     */
32    @Test
33    public void _warmup() throws Exception {
34        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
35            harness.doHover("file:///dropwizard-metrics/src/main/java/io/dropwizard/metrics/MetricsFactory.java", 83, 45);
36        }
37    }
38
39    @Test(timeout = 15000)
40    public void a_coldXDefinition() throws Exception {
41        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
42            long start = System.currentTimeMillis();
43            harness.expectXDefinition("file:///dropwizard-metrics/src/main/java/io/dropwizard/metrics/MetricsFactory.java",
44                    83, 45,
45                    TextDocumentXDefinitionResult.of(
46                            SymbolLocationInformation.of(
47                                    Location.of("file:///dropwizard-metrics/src/main/java/io/dropwizard/metrics/MetricsFactory.java", 48, 43, 48, 52),
48                                    SymbolDescriptor.of(ElementKind.FIELD, "reporters", "io.dropwizard.metrics.MetricsFactory.reporters", "MetricsFactory", "io.dropwizard.metrics", PackageIdentifier.of(PackageIdentifier.Type.MAVEN, "io.dropwizard:dropwizard-metrics", "1.2.0-SNAPSHOT", null, null))
49                            )
50                    )
51            );
52            LOG.info("Cold XDefinition took {}", (System.currentTimeMillis() - start) / 1000.0);
53        }
54    }
55
56    @Ignore // TODO: do this in a way that doesn't send messages to a server that's received a shutdown request
57    @Test(timeout = 100)
58    public void a_warmXDefinition() throws Exception {
59        try (Harness harness = BenchmarkTestBase.getHarness()) {
60            long start = System.currentTimeMillis();
61            harness.expectXDefinition("file:///dropwizard-metrics/src/main/java/io/dropwizard/metrics/MetricsFactory.java",
62                    83, 45,
63                    TextDocumentXDefinitionResult.of(
64                            SymbolLocationInformation.of(
65                                    Location.of("file:///dropwizard-metrics/src/main/java/io/dropwizard/metrics/MetricsFactory.java", 48, 43, 48, 52),
66                                    SymbolDescriptor.of(ElementKind.FIELD, "reporters", "io.dropwizard.metrics.MetricsFactory.reporters", "MetricsFactory", "io.dropwizard.metrics", PackageIdentifier.of(PackageIdentifier.Type.MAVEN, "io.dropwizard:dropwizard-metrics", "1.2.0-SNAPSHOT", null, null))
67                            )
68                    )
69            );
70            LOG.info("Warm XDefinition took {}", (System.currentTimeMillis() - start) / 1000.0);
71        }
72    }
73
74    @Test(timeout = 15000)
75    public void b_coldSymbol() throws Exception {
76        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
77            long start = System.currentTimeMillis();
78            harness.expectWorkspaceSymbol("AssetsBundle",
79                    WorkspaceSymbolResult.of(
80                            SymbolInformation.of("AssetsBundle", SymbolKind.CLASS, "io.dropwizard.assets", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 16, 13, 16, 25)),
81                            SymbolInformation.of("AssetsBundle()", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 34, 11, 34, 23)),
82                            SymbolInformation.of("AssetsBundle(String path)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 47, 11, 47, 23)),
83                            SymbolInformation.of("AssetsBundle(String resourcePath, String uriPath)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 61, 11, 61, 23)),
84                            SymbolInformation.of("AssetsBundle(String resourcePath, String uriPath, String indexFile)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 76, 11, 76, 23)),
85                            SymbolInformation.of("AssetsBundle(String resourcePath, String uriPath, String indexFile, String assetsName)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 92, 11, 92, 23)),
86                            SymbolInformation.of("AssetsBundleTest", SymbolKind.CLASS, "io.dropwizard.assets", Location.of("file:///dropwizard-assets/src/test/java/io/dropwizard/assets/AssetsBundleTest.java", 22, 13, 22, 29)),
87                            SymbolInformation.of("canSupportDiffrentAssetsBundleName()", SymbolKind.METHOD, "AssetsBundleTest", Location.of("file:///dropwizard-assets/src/test/java/io/dropwizard/assets/AssetsBundleTest.java", 86, 16, 86, 50))
88                    )
89
90            );
91            LOG.info("Cold Symbol took {}", (System.currentTimeMillis() - start) / 1000.0);
92        }
93    }
94
95    @Ignore // TODO: do this in a way that doesn't send messages to a server that's received a shutdown request
96    @Test(timeout = 300)
97    public void b_warmSymbol() throws Exception {
98        try (Harness harness = BenchmarkTestBase.getHarness()) {
99            long start = System.currentTimeMillis();
100            harness.expectWorkspaceSymbol("AssetsBundle",
101                    WorkspaceSymbolResult.of(
102                            SymbolInformation.of("AssetsBundle", SymbolKind.CLASS, "io.dropwizard.assets", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 16, 13, 16, 25)),
103                            SymbolInformation.of("AssetsBundle()", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 34, 11, 34, 23)),
104                            SymbolInformation.of("AssetsBundle(String path)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 47, 11, 47, 23)),
105                            SymbolInformation.of("AssetsBundle(String resourcePath, String uriPath)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 61, 11, 61, 23)),
106                            SymbolInformation.of("AssetsBundle(String resourcePath, String uriPath, String indexFile)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 76, 11, 76, 23)),
107                            SymbolInformation.of("AssetsBundle(String resourcePath, String uriPath, String indexFile, String assetsName)", SymbolKind.METHOD, "AssetsBundle", Location.of("file:///dropwizard-assets/src/main/java/io/dropwizard/assets/AssetsBundle.java", 92, 11, 92, 23)),
108                            SymbolInformation.of("AssetsBundleTest", SymbolKind.CLASS, "io.dropwizard.assets", Location.of("file:///dropwizard-assets/src/test/java/io/dropwizard/assets/AssetsBundleTest.java", 22, 13, 22, 29)),
109                            SymbolInformation.of("canSupportDiffrentAssetsBundleName()", SymbolKind.METHOD, "AssetsBundleTest", Location.of("file:///dropwizard-assets/src/test/java/io/dropwizard/assets/AssetsBundleTest.java", 86, 16, 86, 50))
110                    )
111            );
112            LOG.info("Warm Symbol took {}", (System.currentTimeMillis() - start) / 1000.0);
113        }
114    }
115
116    @Test(timeout = 90000)
117    public void c_coldReferences() throws Exception {
118        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
119            long start = System.currentTimeMillis();
120            harness.expectReferences("file:///dropwizard-core/src/main/java/io/dropwizard/Configuration.java",
121                    61, 13,
122                    false,
123                    TextDocumentReferencesResult.of(
124                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/DropwizardApacheConnectorTest.java", 60, 42, 60, 55),
125                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/DropwizardApacheConnectorTest.java", 227, 60, 227, 73),
126                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/DropwizardApacheConnectorTest.java", 233, 24, 233, 37),
127                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/JerseyIgnoreRequestUserAgentHeaderFilterTest.java", 25, 42, 25, 55),
128                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/JerseyIgnoreRequestUserAgentHeaderFilterTest.java", 90, 60, 90, 73),
129                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/JerseyIgnoreRequestUserAgentHeaderFilterTest.java", 96, 24, 96, 37),
130                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/ssl/DropwizardSSLConnectionSocketFactoryTest.java", 52, 63, 52, 76),
131                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/ssl/DropwizardSSLConnectionSocketFactoryTest.java", 58, 24, 58, 37),
132                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/ssl/DropwizardSSLConnectionSocketFactoryTest.java", 64, 42, 64, 55),
133                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/Application.java", 23, 44, 23, 57),
134                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/Application.java", 43, 53, 43, 66),
135                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/CheckCommand.java", 14, 36, 14, 49),
136                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/ConfiguredCommand.java", 25, 50, 25, 63),
137                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/ConfiguredCommand.java", 41, 53, 41, 66),
138                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/EnvironmentCommand.java", 14, 51, 14, 64),
139                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/ServerCommand.java", 17, 37, 17, 50),
140                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/setup/Bootstrap.java", 40, 33, 40, 46),
141                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ApplicationTest.java", 11, 51, 11, 64),
142                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 15, 18, 15, 31),
143                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 15, 52, 15, 65),
144                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 52, 14, 52, 27),
145                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 52, 57, 52, 70),
146                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 14, 59, 14, 72),
147                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 16, 24, 16, 37),
148                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 21, 31, 21, 44),
149                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 24, 28, 24, 41),
150                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 26, 18, 26, 31),
151                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 26, 53, 26, 66),
152                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 31, 30, 31, 43),
153                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 31, 67, 31, 80),
154                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 31, 67, 31, 80),
155                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 33, 24, 33, 37),
156                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 36, 28, 36, 41),
157                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 39, 31, 39, 44),
158                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 60, 86, 60, 99),
159                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 189, 85, 189, 98),
160                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 214, 85, 214, 98),
161                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 295, 69, 295, 82),
162                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 35, 30, 35, 43),
163                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 35, 67, 35, 80),
164                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 35, 67, 35, 80),
165                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 37, 24, 37, 37),
166                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 49, 24, 49, 37),
167                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 16, 63, 16, 76),
168                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 22, 37, 22, 50),
169                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 22, 84, 22, 97),
170                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 27, 59, 27, 72),
171                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 29, 24, 29, 37),
172                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 35, 28, 35, 41),
173                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 42, 29, 42, 42),
174                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 28, 58, 28, 71),
175                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 30, 47, 30, 60),
176                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 35, 59, 35, 72),
177                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 37, 47, 37, 60),
178                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 43, 24, 43, 37),
179                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 54, 18, 54, 31),
180                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 54, 53, 54, 66),
181                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 104, 24, 104, 37),
182                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 108, 51, 108, 64),
183                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 108, 51, 108, 64),
184                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 111, 47, 111, 60),
185                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 111, 106, 111, 119),
186                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 21, 59, 21, 72),
187                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 23, 24, 23, 37),
188                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 28, 32, 28, 45),
189                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 43, 18, 43, 31),
190                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 43, 53, 43, 66),
191                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 29, 30, 29, 43),
192                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 29, 75, 29, 88),
193                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 29, 75, 29, 88),
194                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 31, 24, 31, 37),
195                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 34, 22, 34, 35),
196                            Location.of("file:///dropwizard-db/src/main/java/io/dropwizard/db/DatabaseConfiguration.java", 4, 49, 4, 62),
197                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/app1/App1.java", 16, 38, 16, 51),
198                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/app1/App1.java", 18, 37, 18, 50),
199                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/app1/App1.java", 23, 20, 23, 33),
200                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/forms/FormsApp.java", 8, 42, 8, 55),
201                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/forms/FormsApp.java", 10, 37, 10, 50),
202                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/forms/FormsApp.java", 15, 20, 15, 33),
203                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/sslreload/SslReloadApp.java", 8, 46, 8, 59),
204                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/sslreload/SslReloadApp.java", 10, 37, 10, 50),
205                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/sslreload/SslReloadApp.java", 15, 20, 15, 33),
206                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/app1/App1Test.java", 23, 42, 23, 55),
207                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/forms/FormsAppTest.java", 25, 42, 25, 55),
208                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/request_log/AbstractRequestLogPatternIntegrationTest.java", 30, 60, 30, 73),
209                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/request_log/AbstractRequestLogPatternIntegrationTest.java", 36, 24, 36, 37),
210                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/request_log/AbstractRequestLogPatternIntegrationTest.java", 60, 29, 60, 42),
211                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/sslreload/SslReloadAppTest.java", 55, 35, 55, 48),
212                            Location.of("file:///dropwizard-example/src/main/java/com/example/helloworld/HelloWorldConfiguration.java", 14, 45, 14, 58),
213                            Location.of("file:///dropwizard-hibernate/src/main/java/io/dropwizard/hibernate/HibernateBundle.java", 14, 48, 14, 61),
214                            Location.of("file:///dropwizard-hibernate/src/main/java/io/dropwizard/hibernate/ScanningHibernateBundle.java", 15, 56, 15, 69),
215                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 31, 18, 31, 31),
216                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 31, 53, 31, 66),
217                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 35, 34, 35, 47),
218                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 35, 78, 35, 91),
219                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 35, 78, 35, 91),
220                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 37, 54, 37, 67),
221                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 106, 30, 106, 43),
222                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 106, 80, 106, 93),
223                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 106, 80, 106, 93),
224                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 108, 58, 108, 71),
225                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/LazyLoadingTest.java", 42, 50, 42, 63),
226                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/FakeApplication.java", 12, 49, 12, 62),
227                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/FakeApplication.java", 17, 20, 17, 33),
228                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/Http2CIntegrationTest.java", 26, 29, 26, 42),
229                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/Http2IntegrationTest.java", 27, 35, 27, 48),
230                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/AbstractLiquibaseCommand.java", 21, 57, 21, 70),
231                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbCalculateChecksumCommand.java", 14, 50, 14, 63),
232                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbClearChecksumsCommand.java", 7, 47, 7, 60),
233                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbCommand.java", 11, 33, 11, 46),
234                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbDropAllCommand.java", 9, 40, 9, 53),
235                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbDumpCommand.java", 41, 37, 41, 50),
236                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbFastForwardCommand.java", 16, 44, 16, 57),
237                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbGenerateDocsCommand.java", 8, 45, 8, 58),
238                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbLocksCommand.java", 14, 38, 14, 51),
239                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbMigrateCommand.java", 17, 40, 17, 53),
240                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbPrepareRollbackCommand.java", 16, 48, 16, 61),
241                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbRollbackCommand.java", 21, 41, 21, 54),
242                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbStatusCommand.java", 17, 39, 17, 52),
243                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbTagCommand.java", 8, 36, 8, 49),
244                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbTestCommand.java", 12, 37, 12, 50),
245                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/MigrationsBundle.java", 8, 49, 8, 62),
246                            Location.of("file:///dropwizard-migrations/src/test/java/io/dropwizard/migrations/TestMigrationConfiguration.java", 5, 48, 5, 61),
247                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/DropwizardTestSupport.java", 40, 45, 40, 58),
248                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/DropwizardTestSupport.java", 268, 59, 268, 72),
249                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/POJOConfigurationFactory.java", 9, 48, 9, 61),
250                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 69, 41, 69, 54),
251                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 201, 59, 201, 72),
252                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 56, 40, 56, 53),
253                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 59, 48, 59, 61),
254                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 59, 48, 59, 61),
255                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 61, 31, 61, 44),
256                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 97, 54, 97, 67),
257                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 99, 24, 99, 37),
258                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/DropwizardTestSupportTest.java", 115, 50, 115, 63),
259                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java", 21, 42, 21, 55),
260                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java", 33, 60, 33, 73),
261                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java", 35, 24, 35, 37),
262                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/TestConfiguration.java", 6, 39, 6, 52),
263                            Location.of("file:///dropwizard-views/src/main/java/io/dropwizard/views/ViewBundle.java", 91, 34, 91, 47),
264                            Location.of("file:///dropwizard-views/src/main/java/io/dropwizard/views/ViewConfigurable.java", 6, 44, 6, 57),
265                            Location.of("file:///dropwizard-views/src/test/java/io/dropwizard/views/ViewBundleTest.java", 37, 49, 37, 62)
266                    )
267            );
268            LOG.info("Cold References took {}", (System.currentTimeMillis() - start) / 1000.0);
269        }
270    }
271
272    @Ignore // TODO: do this in a way that doesn't send messages to a server that's received a shutdown request
273    @Test(timeout = 1500)
274    public void c_warmReferences() throws Exception {
275        try (Harness harness = BenchmarkTestBase.getHarness()) {
276            long start = System.currentTimeMillis();
277            harness.expectReferences("file:///dropwizard-core/src/main/java/io/dropwizard/Configuration.java",
278                    61, 13,
279                    false,
280                    TextDocumentReferencesResult.of(
281                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/DropwizardApacheConnectorTest.java", 60, 42, 60, 55),
282                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/DropwizardApacheConnectorTest.java", 227, 60, 227, 73),
283                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/DropwizardApacheConnectorTest.java", 233, 24, 233, 37),
284                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/JerseyIgnoreRequestUserAgentHeaderFilterTest.java", 25, 42, 25, 55),
285                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/JerseyIgnoreRequestUserAgentHeaderFilterTest.java", 90, 60, 90, 73),
286                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/JerseyIgnoreRequestUserAgentHeaderFilterTest.java", 96, 24, 96, 37),
287                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/ssl/DropwizardSSLConnectionSocketFactoryTest.java", 52, 63, 52, 76),
288                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/ssl/DropwizardSSLConnectionSocketFactoryTest.java", 58, 24, 58, 37),
289                            Location.of("file:///dropwizard-client/src/test/java/io/dropwizard/client/ssl/DropwizardSSLConnectionSocketFactoryTest.java", 64, 42, 64, 55),
290                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/Application.java", 23, 44, 23, 57),
291                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/Application.java", 43, 53, 43, 66),
292                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/CheckCommand.java", 14, 36, 14, 49),
293                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/ConfiguredCommand.java", 25, 50, 25, 63),
294                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/ConfiguredCommand.java", 41, 53, 41, 66),
295                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/EnvironmentCommand.java", 14, 51, 14, 64),
296                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/cli/ServerCommand.java", 17, 37, 17, 50),
297                            Location.of("file:///dropwizard-core/src/main/java/io/dropwizard/setup/Bootstrap.java", 40, 33, 40, 46),
298                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ApplicationTest.java", 11, 51, 11, 64),
299                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 15, 18, 15, 31),
300                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 15, 52, 15, 65),
301                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 52, 14, 52, 27),
302                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/ConfigurationTest.java", 52, 57, 52, 70),
303                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 14, 59, 14, 72),
304                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 16, 24, 16, 37),
305                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 21, 31, 21, 44),
306                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 24, 28, 24, 41),
307                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 26, 18, 26, 31),
308                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CheckCommandTest.java", 26, 53, 26, 66),
309                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 31, 30, 31, 43),
310                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 31, 67, 31, 80),
311                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 31, 67, 31, 80),
312                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 33, 24, 33, 37),
313                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 36, 28, 36, 41),
314                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 39, 31, 39, 44),
315                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 60, 86, 60, 99),
316                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 189, 85, 189, 98),
317                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 214, 85, 214, 98),
318                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CliTest.java", 295, 69, 295, 82),
319                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 35, 30, 35, 43),
320                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 35, 67, 35, 80),
321                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 35, 67, 35, 80),
322                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 37, 24, 37, 37),
323                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/CommandTest.java", 49, 24, 49, 37),
324                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 16, 63, 16, 76),
325                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 22, 37, 22, 50),
326                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 22, 84, 22, 97),
327                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 27, 59, 27, 72),
328                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 29, 24, 29, 37),
329                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 35, 28, 35, 41),
330                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ConfiguredCommandTest.java", 42, 29, 42, 42),
331                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 28, 58, 28, 71),
332                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 30, 47, 30, 60),
333                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 35, 59, 35, 72),
334                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 37, 47, 37, 60),
335                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 43, 24, 43, 37),
336                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 54, 18, 54, 31),
337                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 54, 53, 54, 66),
338                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 104, 24, 104, 37),
339                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 108, 51, 108, 64),
340                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 108, 51, 108, 64),
341                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 111, 47, 111, 60),
342                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/InheritedServerCommandTest.java", 111, 106, 111, 119),
343                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 21, 59, 21, 72),
344                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 23, 24, 23, 37),
345                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 28, 32, 28, 45),
346                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 43, 18, 43, 31),
347                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/cli/ServerCommandTest.java", 43, 53, 43, 66),
348                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 29, 30, 29, 43),
349                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 29, 75, 29, 88),
350                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 29, 75, 29, 88),
351                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 31, 24, 31, 37),
352                            Location.of("file:///dropwizard-core/src/test/java/io/dropwizard/setup/BootstrapTest.java", 34, 22, 34, 35),
353                            Location.of("file:///dropwizard-db/src/main/java/io/dropwizard/db/DatabaseConfiguration.java", 4, 49, 4, 62),
354                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/app1/App1.java", 16, 38, 16, 51),
355                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/app1/App1.java", 18, 37, 18, 50),
356                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/app1/App1.java", 23, 20, 23, 33),
357                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/forms/FormsApp.java", 8, 42, 8, 55),
358                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/forms/FormsApp.java", 10, 37, 10, 50),
359                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/forms/FormsApp.java", 15, 20, 15, 33),
360                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/sslreload/SslReloadApp.java", 8, 46, 8, 59),
361                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/sslreload/SslReloadApp.java", 10, 37, 10, 50),
362                            Location.of("file:///dropwizard-e2e/src/main/java/com/example/sslreload/SslReloadApp.java", 15, 20, 15, 33),
363                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/app1/App1Test.java", 23, 42, 23, 55),
364                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/forms/FormsAppTest.java", 25, 42, 25, 55),
365                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/request_log/AbstractRequestLogPatternIntegrationTest.java", 30, 60, 30, 73),
366                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/request_log/AbstractRequestLogPatternIntegrationTest.java", 36, 24, 36, 37),
367                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/request_log/AbstractRequestLogPatternIntegrationTest.java", 60, 29, 60, 42),
368                            Location.of("file:///dropwizard-e2e/src/test/java/com/example/sslreload/SslReloadAppTest.java", 55, 35, 55, 48),
369                            Location.of("file:///dropwizard-example/src/main/java/com/example/helloworld/HelloWorldConfiguration.java", 14, 45, 14, 58),
370                            Location.of("file:///dropwizard-hibernate/src/main/java/io/dropwizard/hibernate/HibernateBundle.java", 14, 48, 14, 61),
371                            Location.of("file:///dropwizard-hibernate/src/main/java/io/dropwizard/hibernate/ScanningHibernateBundle.java", 15, 56, 15, 69),
372                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 31, 18, 31, 31),
373                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 31, 53, 31, 66),
374                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 35, 34, 35, 47),
375                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 35, 78, 35, 91),
376                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 35, 78, 35, 91),
377                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 37, 54, 37, 67),
378                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 106, 30, 106, 43),
379                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 106, 80, 106, 93),
380                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 106, 80, 106, 93),
381                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/HibernateBundleTest.java", 108, 58, 108, 71),
382                            Location.of("file:///dropwizard-hibernate/src/test/java/io/dropwizard/hibernate/LazyLoadingTest.java", 42, 50, 42, 63),
383                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/FakeApplication.java", 12, 49, 12, 62),
384                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/FakeApplication.java", 17, 20, 17, 33),
385                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/Http2CIntegrationTest.java", 26, 29, 26, 42),
386                            Location.of("file:///dropwizard-http2/src/test/java/io/dropwizard/http2/Http2IntegrationTest.java", 27, 35, 27, 48),
387                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/AbstractLiquibaseCommand.java", 21, 57, 21, 70),
388                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbCalculateChecksumCommand.java", 14, 50, 14, 63),
389                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbClearChecksumsCommand.java", 7, 47, 7, 60),
390                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbCommand.java", 11, 33, 11, 46),
391                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbDropAllCommand.java", 9, 40, 9, 53),
392                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbDumpCommand.java", 41, 37, 41, 50),
393                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbFastForwardCommand.java", 16, 44, 16, 57),
394                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbGenerateDocsCommand.java", 8, 45, 8, 58),
395                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbLocksCommand.java", 14, 38, 14, 51),
396                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbMigrateCommand.java", 17, 40, 17, 53),
397                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbPrepareRollbackCommand.java", 16, 48, 16, 61),
398                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbRollbackCommand.java", 21, 41, 21, 54),
399                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbStatusCommand.java", 17, 39, 17, 52),
400                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbTagCommand.java", 8, 36, 8, 49),
401                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/DbTestCommand.java", 12, 37, 12, 50),
402                            Location.of("file:///dropwizard-migrations/src/main/java/io/dropwizard/migrations/MigrationsBundle.java", 8, 49, 8, 62),
403                            Location.of("file:///dropwizard-migrations/src/test/java/io/dropwizard/migrations/TestMigrationConfiguration.java", 5, 48, 5, 61),
404                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/DropwizardTestSupport.java", 40, 45, 40, 58),
405                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/DropwizardTestSupport.java", 268, 59, 268, 72),
406                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/POJOConfigurationFactory.java", 9, 48, 9, 61),
407                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 69, 41, 69, 54),
408                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 201, 59, 201, 72),
409                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 56, 40, 56, 53),
410                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 59, 48, 59, 61),
411                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 59, 48, 59, 61),
412                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 61, 31, 61, 44),
413                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 97, 54, 97, 67),
414                            Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 99, 24, 99, 37),
415                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/DropwizardTestSupportTest.java", 115, 50, 115, 63),
416                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java", 21, 42, 21, 55),
417                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java", 33, 60, 33, 73),
418                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java", 35, 24, 35, 37),
419                            Location.of("file:///dropwizard-testing/src/test/java/io/dropwizard/testing/junit/TestConfiguration.java", 6, 39, 6, 52),
420                            Location.of("file:///dropwizard-views/src/main/java/io/dropwizard/views/ViewBundle.java", 91, 34, 91, 47),
421                            Location.of("file:///dropwizard-views/src/main/java/io/dropwizard/views/ViewConfigurable.java", 6, 44, 6, 57),
422                            Location.of("file:///dropwizard-views/src/test/java/io/dropwizard/views/ViewBundleTest.java", 37, 49, 37, 62)
423                    )
424            );
425            LOG.info("Warm References took {}", (System.currentTimeMillis() - start) / 1000.0);
426        }
427    }
428
429    @Test(timeout = 60000)
430    public void d_coldXReferences() throws Exception {
431        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
432            long start = System.currentTimeMillis();
433            SymbolDescriptor descriptor = SymbolDescriptor.of(
434                    ElementKind.CLASS,
435                    "ExternalResource",
436                    "org.junit.rules.ExternalResource",
437                    "ExternalResource",
438                    "org.junit.rules",
439                    null
440            );
441
442            harness.expectXReferences(descriptor, Maps.newHashMap(),
443                    WorkspaceXReferencesResult.of(
444                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DBIClient.java", 9, 23, 9, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
445                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DBIClient.java", 19, 31, 19, 47), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
446                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DatabaseInTimeZone.java", 3, 23, 3, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
447                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DatabaseInTimeZone.java", 13, 40, 13, 56), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
448                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DAOTestRule.java", 10, 23, 10, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
449                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DAOTestRule.java", 47, 33, 47, 49), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
450                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 13, 23, 13, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
451                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 69, 64, 69, 80), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
452                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 10, 23, 10, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
453                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 54, 42, 54, 58), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null))
454                    )
455            );
456            LOG.info("Cold XReferences took {}", (System.currentTimeMillis() - start) / 1000.0);
457        }
458    }
459
460    @Ignore // TODO: do this in a way that doesn't send messages to a server that's received a shutdown request
461    @Test(timeout = 1000)
462    public void d_warmXReferences() throws Exception {
463        try (Harness harness = BenchmarkTestBase.getHarness()) {
464            long start = System.currentTimeMillis();
465            SymbolDescriptor descriptor = SymbolDescriptor.of(
466                    ElementKind.CLASS,
467                    "ExternalResource",
468                    "org.junit.rules.ExternalResource",
469                    "ExternalResource",
470                    "org.junit.rules",
471                    null
472            );
473
474            harness.expectXReferences(descriptor, Maps.newHashMap(),
475                    WorkspaceXReferencesResult.of(
476                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DBIClient.java", 9, 23, 9, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
477                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DBIClient.java", 19, 31, 19, 47), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
478                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DatabaseInTimeZone.java", 3, 23, 3, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
479                            ReferenceInformation.of(Location.of("file:///dropwizard-jdbi/src/test/java/io/dropwizard/jdbi/timestamps/DatabaseInTimeZone.java", 13, 40, 13, 56), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
480                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DAOTestRule.java", 10, 23, 10, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
481                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DAOTestRule.java", 47, 33, 47, 49), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
482                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 13, 23, 13, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
483                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardAppRule.java", 69, 64, 69, 80), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
484                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 10, 23, 10, 39), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null)),
485                            ReferenceInformation.of(Location.of("file:///dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DropwizardClientRule.java", 54, 42, 54, 58), SymbolDescriptor.of(ElementKind.CLASS, "ExternalResource", "org.junit.rules.ExternalResource", "ExternalResource", "org.junit.rules", null))
486                    )
487            );
488            LOG.info("Warm XReferences took {}", (System.currentTimeMillis() - start) / 1000.0);
489        }
490    }
491
492    @Test(timeout = 12000)
493    public void e_ReferencesToLocalVar() throws Exception {
494        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
495            long start = System.currentTimeMillis();
496            harness.expectReferences("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java",
497                    42, 21,
498                    false,
499                    TextDocumentReferencesResult.of(
500                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 37, 13, 37, 23),
501                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 42, 13, 42, 23),
502                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 57, 68, 57, 78),
503                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 58, 83, 58, 93),
504                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 81, 12, 81, 22),
505                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 82, 29, 82, 39)
506                    )
507            );
508            LOG.info("Cold References (local var) took {}", (System.currentTimeMillis() - start) / 1000.0);
509        }
510    }
511
512    @Test(timeout = 12000)
513    public void f_ReferencesToPackageLevelElement() throws Exception {
514        try (Harness harness = BenchmarkTestBase.makeHarness(REPO)) {
515            long start = System.currentTimeMillis();
516            harness.expectReferences("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/WebApplicationExceptionCatchingFilter.java",
517                    14, 37,
518                    false,
519                    TextDocumentReferencesResult.of(
520                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/AuthDynamicFeature.java", 58, 45, 58, 82),
521                            Location.of("file:///dropwizard-auth/src/main/java/io/dropwizard/auth/PolymorphicAuthDynamicFeature.java", 50, 45, 50, 82)
522
523                    )
524            );
525            LOG.info("Cold References (local var) took {}", (System.currentTimeMillis() - start) / 1000.0);
526        }
527    }
528
529}
530
Full Screen
copy
1public class TestApp {
2    @Rule
3    public Timeout globalTimeout = new Timeout(20, TimeUnit.MILLISECONDS);
4
5    ......
6    ......
7
8 }
9
Full Screen
copy
1public class TempFolderTest {
2
3 @Rule
4 public TemporaryFolder tempFolder= new TemporaryFolder();
5
6 @Test
7 public void testTempFolder() throws IOException {
8  File folder = tempFolder.newFolder("demos");
9  File file = tempFolder.newFile("Hello.txt");
10
11  assertEquals(folder.getName(), "demos");
12  assertEquals(file.getName(), "Hello.txt");
13
14 }
15
16
17}
18
Full Screen
copy
1public class JunitRuleTest {
2
3  @Rule
4  public TemporaryFolder tempFolder = new TemporaryFolder();
5
6  @Test
7  public void testRule() throws IOException {
8    File newFolder = tempFolder.newFolder("Temp Folder");
9    assertTrue(newFolder.exists());
10  }
11} 
12
Full Screen
copy
1String myResource = IOUtils.toString(this.getClass().getResourceAsStream("yourfile.xml")).replace("\n","");
2
Full Screen
copy
1public String loadResourceAsString(String fileName) throws IOException {
2    Scanner scanner = new Scanner(getClass().getClassLoader().getResourceAsStream(fileName));
3    String contents = scanner.useDelimiter("\\A").next();
4    scanner.close();
5    return contents;
6}
7
Full Screen
copy
1public class FooTest
2{
3    private BufferedReader in = null;
4
5    @Before
6    public void setup()
7        throws IOException
8    {
9        in = new BufferedReader(
10            new InputStreamReader(getClass().getResourceAsStream("/data.txt")));
11    }
12
13    @After
14    public void teardown()
15        throws IOException
16    {
17        if (in != null)
18        {
19            in.close();
20        }
21
22        in = null;
23    }
24
25    @Test
26    public void testFoo()
27        throws IOException
28    {
29        String line = in.readLine();
30
31        assertThat(line, notNullValue());
32    }
33}
34
Full Screen
copy
1URL url = this.getClass().getResource("/test.wsdl");
2File testWsdl = new File(url.getFile());
3
Full Screen
copy
1public static class UsesExternalResource {
2    Server myServer = new Server();
3
4    @Rule public ExternalResource resource = new ExternalResource() {
5        @Override
6        protected void before() throws Throwable {
7            myServer.connect();
8        };
9
10        @Override
11        protected void after() {
12            myServer.disconnect();
13        };
14    };
15
16    @Test public void testFoo() {
17        new Client().run(myServer);
18    }
19}
20
Full Screen
copy
1import static org.junit.Assert.*;
2
3import org.junit.Rule;
4import org.junit.Test;
5import org.junit.rules.ExternalResource;
6
7public class TestSomething
8{
9    @Rule
10    public ResourceFile res = new ResourceFile("/res.txt");
11
12    @Test
13    public void test() throws Exception
14    {
15        assertTrue(res.getContent().length() > 0);
16        assertTrue(res.getFile().exists());
17    }
18}
19
Full Screen
copy
1import java.io.BufferedReader;
2import java.io.File;
3import java.io.FileOutputStream;
4import java.io.FileReader;
5import java.io.IOException;
6import java.io.InputStream;
7import java.io.InputStreamReader;
8import java.nio.charset.Charset;
9
10import org.junit.rules.ExternalResource;
11
12public class ResourceFile extends ExternalResource
13{
14    String res;
15    File file = null;
16    InputStream stream;
17
18    public ResourceFile(String res)
19    {
20        this.res = res;
21    }
22
23    public File getFile() throws IOException
24    {
25        if (file == null)
26        {
27            createFile();
28        }
29        return file;
30    }
31
32    public InputStream getInputStream()
33    {
34        return stream;
35    }
36
37    public InputStream createInputStream()
38    {
39        return getClass().getResourceAsStream(res);
40    }
41
42    public String getContent() throws IOException
43    {
44        return getContent("utf-8");
45    }
46
47    public String getContent(String charSet) throws IOException
48    {
49        InputStreamReader reader = new InputStreamReader(createInputStream(),
50            Charset.forName(charSet));
51        char[] tmp = new char[4096];
52        StringBuilder b = new StringBuilder();
53        try
54        {
55            while (true)
56            {
57                int len = reader.read(tmp);
58                if (len < 0)
59                {
60                    break;
61                }
62                b.append(tmp, 0, len);
63            }
64            reader.close();
65        }
66        finally
67        {
68            reader.close();
69        }
70        return b.toString();
71    }
72
73    @Override
74    protected void before() throws Throwable
75    {
76        super.before();
77        stream = getClass().getResourceAsStream(res);
78    }
79
80    @Override
81    protected void after()
82    {
83        try
84        {
85            stream.close();
86        }
87        catch (IOException e)
88        {
89            // ignore
90        }
91        if (file != null)
92        {
93            file.delete();
94        }
95        super.after();
96    }
97
98    private void createFile() throws IOException
99    {
100        file = new File(".",res);
101        InputStream stream = getClass().getResourceAsStream(res);
102        try
103        {
104            file.createNewFile();
105            FileOutputStream ostream = null;
106            try
107            {
108                ostream = new FileOutputStream(file);
109                byte[] buffer = new byte[4096];
110                while (true)
111                {
112                    int len = stream.read(buffer);
113                    if (len < 0)
114                    {
115                        break;
116                    }
117                    ostream.write(buffer, 0, len);
118                }
119            }
120            finally
121            {
122                if (ostream != null)
123                {
124                    ostream.close();
125                }
126            }
127        }
128        finally
129        {
130            stream.close();
131        }
132    }
133
134}
135
Full Screen
copy
1maven {
2   url = "https://s3-us-west-2.amazonaws.com/dynamodb-local/release"
3}
4
Full Screen
copy
1dependencies {
2    ...
3    runtime files('libs/DynamoDBLocal.jar')
4    ...
5}
6
Full Screen
copy
1repositories {
2    // ... other dependencies
3    maven { url 'https://s3-us-west-2.amazonaws.com/dynamodb-local/release' } 
4}
5
6dependencies {
7    testImplementation("com.amazonaws:DynamoDBLocal:1.13.6")
8}
9
10import org.gradle.internal.os.OperatingSystem
11test {
12    doFirst {
13        // Fix for: UnsatisfiedLinkError -> provide a valid native lib path
14        String nativePrefix = OperatingSystem.current().nativePrefix
15        File nativeLib = sourceSets.test.runtimeClasspath.files.find {it.name.startsWith("libsqlite4java") && it.name.contains(nativePrefix) } as File
16        systemProperty "sqlite4java.library.path", nativeLib.parent
17    }
18}
19
Full Screen
copy
1private lateinit var db: AmazonDynamoDBLocal
2
3@BeforeAll
4fun runDb() { db = DynamoDBEmbedded.create() }
5
6@AfterAll
7fun shutdownDb() { db.shutdown() }
8
Full Screen
copy
1when(mockAmazonDynamoDBClient.getItem(isA(GetItemRequest.class))).thenAnswer(new Answer<GetItemResult>() {
2        @Override
3        public GetItemResult answer(InvocationOnMock invocation) throws Throwable {
4            GetItemResult result = new GetItemResult();
5            result.setItem( testResultItem );
6            return result;
7        }
8    });
9
Full Screen
copy
1import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
2import com.amazonaws.services.dynamodbv2.local.shared.access.AmazonDynamoDBLocal;
3import com.google.common.collect.MoreCollectors;
4import java.io.File;
5import java.util.Arrays;
6import java.util.stream.Stream;
7import org.junit.jupiter.api.condition.OS;
8
9... 
10
11  public AmazonDynamoDBLocal embeddedDynamoDb() {
12    final OS os = Stream.of(OS.values()).filter(OS::isCurrentOs)
13        .collect(MoreCollectors.onlyElement());
14    final String prefix;
15    switch (os) {
16      case LINUX:
17        prefix = "libsqlite4java-linux-amd64-";
18        break;
19      case MAC:
20        prefix = "libsqlite4java-osx-";
21        break;
22      case WINDOWS:
23        prefix = "sqlite4java-win32-x64-";
24        break;
25      default:
26        throw new UnsupportedOperationException(os.toString());
27    }
28  
29    System.setProperty("sqlite4java.library.path",
30        Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator))
31            .stream()
32            .map(File::new)
33            .filter(file -> file.getName().startsWith(prefix))
34            .collect(MoreCollectors.onlyElement())
35            .getParent());
36    return DynamoDBEmbedded.create();
37  }
38
Full Screen
copy
1dependencies {
2  testImplementation "app.cash.tempest:tempest-testing-jvm:1.5.2"
3  testImplementation "app.cash.tempest:tempest-testing-junit5:1.5.2"
4}
5// Or
6dependencies {
7  testImplementation "app.cash.tempest:tempest-testing-docker:1.5.2"
8  testImplementation "app.cash.tempest:tempest-testing-junit5:1.5.2"
9}
10
Full Screen
copy
1dependencies {
2  testImplementation "app.cash.tempest:tempest2-testing-jvm:1.5.2"
3  testImplementation "app.cash.tempest:tempest2-testing-junit5:1.5.2"
4}
5// Or
6dependencies {
7  testImplementation "app.cash.tempest:tempest2-testing-docker:1.5.2"
8  testImplementation "app.cash.tempest:tempest2-testing-junit5:1.5.2"
9}
10
Full Screen
copy
1class MyTest {
2  @RegisterExtension
3  TestDynamoDb db = new TestDynamoDb.Builder(JvmDynamoDbServer.Factory.INSTANCE) // or DockerDynamoDbServer
4      // `MusicItem` is annotated with `@DynamoDBTable`. Tempest recreates this table before each test.
5      .addTable(TestTable.create(MusicItem.TABLE_NAME, MusicItem.class))
6      .build();
7
8  @Test
9  public void test() {
10    PutItemRequest request = // ...;
11    // Talk to the local DynamoDB.
12    db.dynamoDb().putItem(request);
13  }
14
15}
16
Full Screen
copy
1<!--Dependency:-->
2<dependencies>
3    <dependency>
4        <groupId>com.amazonaws</groupId>
5        <artifactId>DynamoDBLocal</artifactId>
6        <version>1.11.0.1</version>
7        <scope>test</scope>
8    </dependency>
9    <dependency>
10      <groupId>com.github.mlk</groupId>
11      <artifactId>assortmentofjunitrules</artifactId>
12      <version>1.5.36</version>
13      <scope>test</scope>
14    </dependency>
15</dependencies>
16<!--Custom repository:-->
17<repositories>
18    <repository>
19        <id>dynamodb-local</id>
20        <name>DynamoDB Local Release Repository</name>
21        <url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</url>
22    </repository>
23</repositories>
24
Full Screen
copy
1repositories {
2  mavenCentral()
3
4   maven {
5    url = "https://s3-us-west-2.amazonaws.com/dynamodb-local/release"
6  }
7}
8
9dependencies {
10    testCompile "com.github.mlk:assortmentofjunitrules:1.5.36"
11    testCompile "com.amazonaws:DynamoDBLocal:1.+"
12}
13
Full Screen
copy
1public class LocalDynamoDbRuleTest {
2  @Rule
3  public LocalDynamoDbRule ddb = new LocalDynamoDbRule();
4
5  @Test
6  public void test() {
7    doDynamoStuff(ddb.getClient());
8  }
9}
10
Full Screen
copy
1import com.amazonaws.services.dynamodbv2.local.main.ServerRunner;
2import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer;
3
4final String[] localArgs = { "-inMemory" };
5DynamoDBProxyServer server = ServerRunner.createServerFromCommandLineArgs(localArgs);
6server.start();
7AmazonDynamoDB dynamodb = new AmazonDynamoDBClient();
8dynamodb.setEndpoint("http://localhost:8000");
9dynamodb.listTables();
10server.stop();
11
Full Screen
copy
1import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded;
2
3AmazonDynamoDB dynamodb = DynamoDBEmbedded.create();
4dynamodb.listTables();
5
Full Screen
copy
1dependencies {
2    testCompile "com.amazonaws:DynamoDBLocal:1.+"
3}
4
Full Screen
copy
1task copyNativeDeps(type: Copy) {
2    from(configurations.compile + configurations.testCompile) {
3        include '*.dll'
4        include '*.dylib'
5        include '*.so'
6    }
7    into 'build/libs'
8}
9
Full Screen
copy
1test {
2    dependsOn copyNativeDeps
3    systemProperty "java.library.path", 'build/libs'
4}
5
Full Screen
copy
1docker run -p 8000:8000 amazon/dynamodb-local
2
Full Screen
copy
1test:
2  stage: test
3  image: openjdk:8-alpine
4  services:
5    - name: amazon/dynamodb-local
6      alias: dynamodb-local
7  script:
8    - DYNAMODB_LOCAL_URL=http://dynamodb-local:8000 ./gradlew clean test
9
Full Screen
copy
1definitions:
2  services:
3    dynamodb-local:
4      image: amazon/dynamodb-local
56step:
7  name: test
8  image:
9    name: openjdk:8-alpine
10  services:
11    - dynamodb-local
12  script:
13    - DYNAMODB_LOCAL_URL=http://localhost:8000 ./gradlew clean test
14
Full Screen
copy
1private AmazonDynamoDB createAmazonDynamoDB(final DynamoDBLocal configuration) {
2    return AmazonDynamoDBClientBuilder
3        .standard()
4        .withEndpointConfiguration(
5            new AwsClientBuilder.EndpointConfiguration(
6                "http://localhost:8000",
7                Regions.US_EAST_1.getName()
8            )
9        )
10        .withCredentials(
11            new AWSStaticCredentialsProvider(
12                // DynamoDB Local works with any non-null credentials
13                new BasicAWSCredentials("", "")
14            )
15        )
16        .build();
17}
18
Full Screen
copy
1<!--Dependency:-->
2<dependencies>
3    <dependency>
4        <groupId>com.amazonaws</groupId>
5        <artifactId>DynamoDBLocal</artifactId>
6        <version>1.11.0.1</version>
7        <scope></scope>
8    </dependency>
9</dependencies>
10<!--Custom repository:-->
11<repositories>
12    <repository>
13        <id>dynamodb-local</id>
14        <name>DynamoDB Local Release Repository</name>
15        <url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</url>
16    </repository>
17</repositories>
18
Full Screen
copy
1<dependency>
2    <groupId>com.almworks.sqlite4java</groupId>
3    <artifactId>sqlite4java</artifactId>
4    <version>1.0.392</version>
5    <scope>test</scope>
6</dependency>
7<dependency>
8    <groupId>com.almworks.sqlite4java</groupId>
9    <artifactId>sqlite4java-win32-x86</artifactId>
10    <version>1.0.392</version>
11    <type>dll</type>
12    <scope>test</scope>
13</dependency>
14<dependency>
15    <groupId>com.almworks.sqlite4java</groupId>
16    <artifactId>sqlite4java-win32-x64</artifactId>
17    <version>1.0.392</version>
18    <type>dll</type>
19    <scope>test</scope>
20</dependency>
21<dependency>
22    <groupId>com.almworks.sqlite4java</groupId>
23    <artifactId>libsqlite4java-osx</artifactId>
24    <version>1.0.392</version>
25    <type>dylib</type>
26    <scope>test</scope>
27</dependency>
28<dependency>
29    <groupId>com.almworks.sqlite4java</groupId>
30    <artifactId>libsqlite4java-linux-i386</artifactId>
31    <version>1.0.392</version>
32    <type>so</type>
33    <scope>test</scope>
34</dependency>
35<dependency>
36    <groupId>com.almworks.sqlite4java</groupId>
37    <artifactId>libsqlite4java-linux-amd64</artifactId>
38    <version>1.0.392</version>
39    <type>so</type>
40    <scope>test</scope>
41</dependency>
42
Full Screen
copy
1<build>
2    <plugins>
3        <plugin>
4            <groupId>org.apache.maven.plugins</groupId>
5            <artifactId>maven-dependency-plugin</artifactId>
6            <version>2.10</version>
7            <executions>
8                <execution>
9                    <id>copy</id>
10                    <phase>test-compile</phase>
11                    <goals>
12                        <goal>copy-dependencies</goal>
13                    </goals>
14                    <configuration>
15                        <includeScope>test</includeScope>
16                        <includeTypes>so,dll,dylib</includeTypes>
17                        <outputDirectory>${project.basedir}/native-libs</outputDirectory>
18                    </configuration>
19                </execution>
20            </executions>
21        </plugin>
22    </plugins>
23</build>
24
Full Screen
copy
1System.setProperty("sqlite4java.library.path", "native-libs");
2
Full Screen
copy
1import com.amazonaws.auth.BasicAWSCredentials;
2import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
3import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
4import com.amazonaws.services.dynamodbv2.local.main.ServerRunner;
5import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer;
6import org.junit.rules.ExternalResource;
7
8import java.io.IOException;
9import java.net.ServerSocket;
10
11/**
12 * Creates a local DynamoDB instance for testing.
13 */
14public class LocalDynamoDBCreationRule extends ExternalResource {
15
16    private DynamoDBProxyServer server;
17    private AmazonDynamoDB amazonDynamoDB;
18
19    public LocalDynamoDBCreationRule() {
20        // This one should be copied during test-compile time. If project's basedir does not contains a folder
21        // named 'native-libs' please try '$ mvn clean install' from command line first
22        System.setProperty("sqlite4java.library.path", "native-libs");
23    }
24
25    @Override
26    protected void before() throws Throwable {
27
28        try {
29            final String port = getAvailablePort();
30            this.server = ServerRunner.createServerFromCommandLineArgs(new String[]{"-inMemory", "-port", port});
31            server.start();
32            amazonDynamoDB = new AmazonDynamoDBClient(new BasicAWSCredentials("access", "secret"));
33            amazonDynamoDB.setEndpoint("http://localhost:" + port);
34        } catch (Exception e) {
35            throw new RuntimeException(e);
36        }
37    }
38
39    @Override
40    protected void after() {
41
42        if (server == null) {
43            return;
44        }
45
46        try {
47            server.stop();
48        } catch (Exception e) {
49            throw new RuntimeException(e);
50        }
51    }
52
53    public AmazonDynamoDB getAmazonDynamoDB() {
54        return amazonDynamoDB;
55    }
56
57    private String getAvailablePort() {
58        try (final ServerSocket serverSocket = new ServerSocket(0)) {
59            return String.valueOf(serverSocket.getLocalPort());
60        } catch (IOException e) {
61            throw new RuntimeException("Available port was not found", e);
62        }
63    }
64}
65
Full Screen
copy
1@RunWith(JUnit4.class)
2public class UserDAOImplTest {
3
4    @ClassRule
5    public static final LocalDynamoDBCreationRule dynamoDB = new LocalDynamoDBCreationRule();
6}
7
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in ExternalResource

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)