Skip to content

Commit 823eb9f

Browse files
committed
Automatically invoke gcd for testing
1 parent ede6867 commit 823eb9f

6 files changed

Lines changed: 324 additions & 61 deletions

File tree

.eclipse-pmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
33
<analysis enabled="true" />
44
<rulesets>
5-
<ruleset name="Full PMD ruleset" ref="full-pmd-ruleset.xml" refcontext="project" />
5+
<ruleset name="Project PMD settings" ref="pmd.xml" refcontext="project" />
66
</rulesets>
77
</eclipse-pmd>

full-pmd-ruleset.xml

Lines changed: 0 additions & 46 deletions
This file was deleted.

pmd.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements"/>
8181
<rule ref="rulesets/vm/basic.xml/CollapsibleIfStatements"/>
8282
<rule ref="rulesets/java/comments.xml/CommentContent"/>
83-
<rule ref="rulesets/java/comments.xml/CommentRequired"/>
8483
<rule ref="rulesets/java/comments.xml/CommentSize"/>
8584
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"/>
8685
<rule ref="rulesets/java/design.xml/ConfusingTernary"/>
@@ -183,7 +182,6 @@
183182
<rule ref="rulesets/java/coupling.xml/LawOfDemeter"/>
184183
<rule ref="rulesets/java/j2ee.xml/LocalHomeNamingConvention"/>
185184
<rule ref="rulesets/java/j2ee.xml/LocalInterfaceSessionNamingConvention"/>
186-
<rule ref="rulesets/java/optimizations.xml/LocalVariableCouldBeFinal"/>
187185
<rule ref="rulesets/java/logging-java.xml/LoggerIsNotStaticFinal"/>
188186
<rule ref="rulesets/java/design.xml/LogicInversion"/>
189187
<rule ref="rulesets/java/migrating.xml/LongInstantiation"/>
@@ -333,4 +331,4 @@
333331
<rule ref="rulesets/java/naming.xml/VariableNamingConventions"/>
334332
<rule ref="rulesets/java/braces.xml/WhileLoopsMustUseBraces"/>
335333
<rule ref="rulesets/ecmascript/braces.xml/WhileLoopsMustUseBraces"/>
336-
</ruleset>
334+
</ruleset>

pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,79 @@
102102
</pluginRepositories>
103103
<build>
104104
<plugins>
105+
<plugin>
106+
<artifactId>maven-antrun-plugin</artifactId>
107+
<version>1.8</version>
108+
<executions>
109+
<execution>
110+
<id>before-integration-test</id>
111+
<phase>pre-integration-test</phase>
112+
<configuration>
113+
<target>
114+
<property name="test_classpath" refid="maven.test.classpath"/>
115+
<java classname="com.google.gcloud.datastore.LocalGcdHelper">
116+
<arg value="START"/>
117+
<classpath>
118+
<pathelement path="${test_classpath}" />
119+
</classpath>
120+
</java>
121+
</target>
122+
</configuration>
123+
<goals>
124+
<goal>run</goal>
125+
</goals>
126+
</execution>
127+
<execution>
128+
<id>after-integration-test</id>
129+
<phase>post-integration-test</phase>
130+
<configuration>
131+
<target>
132+
<property name="test_classpath" refid="maven.test.classpath"/>
133+
<java classname="com.google.gcloud.datastore.LocalGcdHelper">
134+
<arg value="STOP"/>
135+
<classpath>
136+
<pathelement path="${test_classpath}" />
137+
</classpath>
138+
</java>
139+
</target>
140+
</configuration>
141+
<goals>
142+
<goal>run</goal>
143+
</goals>
144+
</execution>
145+
</executions>
146+
</plugin>
147+
<plugin>
148+
<groupId>org.apache.maven.plugins</groupId>
149+
<artifactId>maven-surefire-plugin</artifactId>
150+
<version>2.18.1</version>
151+
<configuration>
152+
<excludes>
153+
<exclude>**/*IntegrationTest.java</exclude>
154+
</excludes>
155+
</configuration>
156+
</plugin>
157+
<plugin>
158+
<groupId>org.apache.maven.plugins</groupId>
159+
<artifactId>maven-failsafe-plugin</artifactId>
160+
<version>2.18.1</version>
161+
<configuration>
162+
<excludes>
163+
<exclude>none</exclude>
164+
</excludes>
165+
<includes>
166+
<include>**/*IntegrationTest.java</include>
167+
</includes>
168+
</configuration>
169+
<executions>
170+
<execution>
171+
<goals>
172+
<goal>integration-test</goal>
173+
<goal>verify</goal>
174+
</goals>
175+
</execution>
176+
</executions>
177+
</plugin>
105178
<plugin>
106179
<artifactId>maven-jar-plugin</artifactId>
107180
<version>2.5</version>

src/test/java/com/google/gcloud/datastore/DatastoreServiceTest.java renamed to src/test/java/com/google/gcloud/datastore/DatastoreServiceIntegrationTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
1818

1919
import org.easymock.EasyMock;
20+
import org.junit.After;
2021
import org.junit.Before;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
2324
import org.junit.runners.JUnit4;
2425

26+
import java.io.IOException;
2527
import java.util.Collections;
2628
import java.util.HashMap;
2729
import java.util.Iterator;
2830
import java.util.List;
2931
import java.util.Map;
3032

3133
@RunWith(JUnit4.class)
32-
public class DatastoreServiceTest {
34+
public class DatastoreServiceIntegrationTest {
3335

34-
private static final String DATASET = "dataset1";
36+
private static final String DATASET = LocalGcdHelper.DEFAULT_DATASET;
3537
private static final String KIND1 = "kind1";
3638
private static final String KIND2 = "kind2";
3739
private static final NullValue NULL_VALUE = NullValue.of();
@@ -70,19 +72,16 @@ public class DatastoreServiceTest {
7072
private DatastoreServiceOptions options;
7173
private DatastoreService datastore;
7274
private DatastoreHelper helper;
75+
private LocalGcdHelper gcdHelper;
7376

7477
@Before
75-
public void setUp() {
76-
// TODO(ozarov): document that this test depends on a local gcd running.
77-
// Unfortunately, the gcd tool is not bundled with the cloud SDK and need
78-
// to be downloaded independently from
79-
// https://cloud.google.com/datastore/docs/tools/devserver (b/16372095).
80-
// To start the gcd run:
81-
// gcd.sh create dataset1; gcd.sh start dataset1
82-
// We should have an option to start the gcd from maven/ant.
78+
public void setUp() throws IOException, InterruptedException {
79+
if (!LocalGcdHelper.isActive(DATASET)) {
80+
gcdHelper = LocalGcdHelper.start(DATASET);
81+
}
8382
options = DatastoreServiceOptions.builder()
8483
.dataset(DATASET)
85-
.host("http://localhost:8080")
84+
.host("http://localhost:" + LocalGcdHelper.PORT)
8685
.build();
8786
datastore = DatastoreServiceFactory.getDefault(options);
8887
helper = DatastoreHelper.createFor(datastore);
@@ -91,6 +90,13 @@ public void setUp() {
9190
datastore.add(ENTITY1, ENTITY2);
9291
}
9392

93+
@After
94+
public void tearDown() throws IOException, InterruptedException {
95+
if (gcdHelper != null) {
96+
gcdHelper.stop();
97+
}
98+
}
99+
94100
@Test
95101
public void testGetOptions() {
96102
assertSame(options, datastore.options());

0 commit comments

Comments
 (0)