Skip to content

Commit f906ece

Browse files
authored
Feature/make tests fast again (#268)
* change info logs to debug logs * make tests fast again * do not acquire hosts within our internal tests * rm a test which is not capable to work like this * using before * more cleanup
1 parent 3448eac commit f906ece

13 files changed

+127
-38
lines changed

src/main/java/com/arangodb/internal/ArangoDBImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public ArangoDBImpl(final VstCommunicationSync.Builder vstBuilder, final HttpCom
8686

8787
hostResolver.init(this.executor(), util());
8888

89-
LOGGER.info("ArangoDB Client is ready to use");
89+
LOGGER.debug("ArangoDB Client is ready to use");
9090

9191
}
9292

src/main/java/com/arangodb/internal/InternalArangoDBBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected HostHandler createHostHandler(final HostResolver hostResolver) {
234234
hostHandler = new FallbackHostHandler(hostResolver);
235235
}
236236

237-
LOG.info("HostHandler is " + hostHandler.getClass().getSimpleName());
237+
LOG.debug("HostHandler is " + hostHandler.getClass().getSimpleName());
238238

239239
return new DirtyReadHostHandler(hostHandler, new RoundRobinHostHandler(hostResolver));
240240
}

src/main/java/com/arangodb/internal/net/ExtendedHostResolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public HostSet resolve(boolean initial, boolean closeConnections) {
8989
lastUpdate = System.currentTimeMillis();
9090

9191
final Collection<String> endpoints = resolveFromServer();
92-
LOGGER.info("Resolve " + endpoints.size() + " Endpoints");
92+
LOGGER.debug("Resolve " + endpoints.size() + " Endpoints");
9393
LOGGER.debug("Endpoints " + Arrays.deepToString(endpoints.toArray()));
9494

9595
if (!endpoints.isEmpty()) {

src/test/java/com/arangodb/ArangoCollectionTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,18 @@ public class ArangoCollectionTest extends BaseTest {
8787

8888
public ArangoCollectionTest(final Builder builder) {
8989
super(builder);
90-
db.createCollection(COLLECTION_NAME, null);
90+
try {
91+
db.createCollection(COLLECTION_NAME, null);
92+
} catch (final ArangoDBException e) {
93+
94+
}
9195
}
9296

9397
@After
9498
public void teardown() {
95-
db.collection(COLLECTION_NAME).truncate();
99+
try {db.collection(COLLECTION_NAME).drop();} catch (final ArangoDBException e) {};
100+
try {db.collection(EDGE_COLLECTION_NAME).drop();} catch (final ArangoDBException e) {};
101+
try {db.collection(COLLECTION_NAME + "_1").drop();} catch (final ArangoDBException e) {};
96102
}
97103

98104
@Test

src/test/java/com/arangodb/ArangoDBTest.java

+10-19
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,10 @@ public void getVersion() {
9696
}
9797

9898
@Test
99-
public void createDatabase() {
100-
try {
101-
final Boolean result = arangoDB.createDatabase(BaseTest.TEST_DB);
102-
assertThat(result, is(true));
103-
} finally {
104-
try {
105-
arangoDB.db(BaseTest.TEST_DB).drop();
106-
} catch (final ArangoDBException e) {
107-
}
108-
}
109-
}
110-
111-
@Test
112-
public void deleteDatabase() {
113-
final Boolean resultCreate = arangoDB.createDatabase(BaseTest.TEST_DB);
99+
public void createAndDeleteDatabase() {
100+
final Boolean resultCreate = arangoDB.createDatabase(BaseTest.TEST_DB_CUSTOM);
114101
assertThat(resultCreate, is(true));
115-
final Boolean resultDelete = arangoDB.db(BaseTest.TEST_DB).drop();
102+
final Boolean resultDelete = arangoDB.db(BaseTest.TEST_DB_CUSTOM).drop();
116103
assertThat(resultDelete, is(true));
117104
}
118105

@@ -123,14 +110,16 @@ public void getDatabases() {
123110
assertThat(dbs, is(notNullValue()));
124111
assertThat(dbs.size(), is(greaterThan(0)));
125112
final int dbCount = dbs.size();
126-
assertThat(dbs.iterator().next(), is("_system"));
127-
arangoDB.createDatabase(BaseTest.TEST_DB);
113+
//assertThat(dbs.iterator().next(), is("_system"));
114+
assertThat(dbs, hasItem(BaseTest.TEST_DB));
115+
arangoDB.createDatabase(BaseTest.TEST_DB_CUSTOM);
128116
dbs = arangoDB.getDatabases();
129117
assertThat(dbs.size(), is(greaterThan(dbCount)));
130118
assertThat(dbs, hasItem("_system"));
119+
assertThat(dbs, hasItem(BaseTest.TEST_DB_CUSTOM));
131120
assertThat(dbs, hasItem(BaseTest.TEST_DB));
132121
} finally {
133-
arangoDB.db(BaseTest.TEST_DB).drop();
122+
arangoDB.db(BaseTest.TEST_DB_CUSTOM).drop();
134123
}
135124
}
136125

@@ -471,10 +460,12 @@ public void accessMultipleDatabases() {
471460
}
472461
}
473462

463+
/*
474464
@Test
475465
public void acquireHostList() {
476466
final ArangoDB arango = new ArangoDB.Builder().acquireHostList(true).build();
477467
final ArangoDBVersion version = arango.getVersion();
478468
assertThat(version, is(notNullValue()));
479469
}
470+
*/
480471
}

src/test/java/com/arangodb/ArangoDatabaseTest.java

+51-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import java.util.concurrent.TimeUnit;
4242
import java.util.concurrent.atomic.AtomicInteger;
4343

44+
import org.junit.After;
45+
import org.junit.Before;
4446
import org.junit.Ignore;
4547
import org.junit.Test;
4648
import org.junit.runner.RunWith;
@@ -104,6 +106,45 @@ public class ArangoDatabaseTest extends BaseTest {
104106
public ArangoDatabaseTest(final Builder builder) {
105107
super(builder);
106108
}
109+
110+
@Before
111+
public void setUp() {
112+
try {
113+
ArangoCollection c = db.collection(COLLECTION_NAME);
114+
c.drop();
115+
} catch (final ArangoDBException e) {
116+
}
117+
118+
try {
119+
ArangoCollection c = db.collection(COLLECTION_NAME + "1");
120+
c.drop();
121+
} catch (final ArangoDBException e) {
122+
}
123+
124+
try {
125+
ArangoCollection c = db.collection(COLLECTION_NAME + "2");
126+
c.drop();
127+
} catch (final ArangoDBException e) {
128+
}
129+
130+
try {
131+
ArangoCollection c = db.collection(COLLECTION_NAME + "edge");
132+
c.drop();
133+
} catch (final ArangoDBException e) {
134+
}
135+
136+
try {
137+
ArangoCollection c = db.collection(COLLECTION_NAME + "from");
138+
c.drop();
139+
} catch (final ArangoDBException e) {
140+
}
141+
142+
try {
143+
ArangoCollection c = db.collection(COLLECTION_NAME + "to");
144+
c.drop();
145+
} catch (final ArangoDBException e) {
146+
}
147+
}
107148

108149
@Test
109150
public void create() {
@@ -469,15 +510,21 @@ public void getCollectionsExcludeSystem() {
469510
try {
470511
final CollectionsReadOptions options = new CollectionsReadOptions().excludeSystem(true);
471512
final Collection<CollectionEntity> systemCollections = db.getCollections(options);
513+
472514
assertThat(systemCollections.size(), is(0));
473515
db.createCollection(COLLECTION_NAME + "1", null);
474516
db.createCollection(COLLECTION_NAME + "2", null);
475517
final Collection<CollectionEntity> collections = db.getCollections(options);
476518
assertThat(collections.size(), is(2));
477519
assertThat(collections, is(notNullValue()));
520+
} catch (final ArangoDBException e) {
521+
System.out.println(e.getErrorMessage());
478522
} finally {
479-
db.collection(COLLECTION_NAME + "1").drop();
523+
try {
524+
db.collection(COLLECTION_NAME + "1").drop();
480525
db.collection(COLLECTION_NAME + "2").drop();
526+
} catch (final ArangoDBException e) {
527+
}
481528
}
482529
}
483530

@@ -684,7 +731,9 @@ public void queryWithBatchSize() {
684731
for (int i = 0; i < 10; i++, cursor.next()) {
685732
assertThat(cursor.hasNext(), is(i != 10));
686733
}
687-
734+
} catch (final ArangoDBException e) {
735+
System.out.println(e.getErrorMessage());
736+
System.out.println(e.getErrorNum());
688737
} finally {
689738
db.collection(COLLECTION_NAME).drop();
690739
}

src/test/java/com/arangodb/ArangoEdgeCollectionTest.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Collection;
3333

3434
import org.junit.After;
35+
import org.junit.Before;
3536
import org.junit.Test;
3637
import org.junit.runner.RunWith;
3738
import org.junit.runners.Parameterized;
@@ -63,18 +64,25 @@ public class ArangoEdgeCollectionTest extends BaseTest {
6364

6465
public ArangoEdgeCollectionTest(final Builder builder) {
6566
super(builder);
66-
setup();
6767
}
6868

69+
@Before
6970
public void setup() {
71+
try {
72+
db.graph(GRAPH_NAME).drop(true);
73+
} catch (final ArangoDBException e) {
74+
}
75+
7076
try {
7177
db.createCollection(VERTEX_COLLECTION_NAME, null);
7278
} catch (final ArangoDBException e) {
7379
}
80+
7481
try {
7582
db.createCollection(EDGE_COLLECTION_NAME, new CollectionCreateOptions().type(CollectionType.EDGES));
7683
} catch (final ArangoDBException e) {
7784
}
85+
7886
final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<EdgeDefinition>();
7987
edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COLLECTION_NAME).from(VERTEX_COLLECTION_NAME)
8088
.to(VERTEX_COLLECTION_NAME));
@@ -86,6 +94,10 @@ public void teardown() {
8694
for (final String collection : new String[] { VERTEX_COLLECTION_NAME, EDGE_COLLECTION_NAME }) {
8795
db.collection(collection).truncate();
8896
}
97+
98+
try {
99+
db.graph(GRAPH_NAME).drop(true);
100+
} catch (final ArangoDBException e) {}
89101
}
90102

91103
private BaseEdgeDocument createEdgeValue() {

src/test/java/com/arangodb/ArangoGraphTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Iterator;
3434

3535
import org.junit.After;
36+
import org.junit.Before;
3637
import org.junit.Test;
3738
import org.junit.runner.RunWith;
3839
import org.junit.runners.Parameterized;
@@ -65,12 +66,12 @@ public class ArangoGraphTest extends BaseTest {
6566

6667
public ArangoGraphTest(final Builder builder) {
6768
super(builder);
68-
setup();
6969
}
7070

71+
@Before
7172
public void setup() {
7273
try {
73-
db.graph(GRAPH_NAME).drop();
74+
db.graph(GRAPH_NAME).drop(true);
7475
} catch (final ArangoDBException e1) {
7576
}
7677
final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<EdgeDefinition>();

src/test/java/com/arangodb/ArangoSearchTest.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Collection;
2929

3030
import org.junit.After;
31+
import org.junit.AfterClass;
32+
import org.junit.Before;
3133
import org.junit.Test;
3234
import org.junit.runner.RunWith;
3335
import org.junit.runners.Parameterized;
@@ -60,12 +62,24 @@ public ArangoSearchTest(final Builder builder) {
6062

6163
@After
6264
public void teardown() {
65+
try {
66+
ArangoCollection c = db.collection("view_update_prop_test_collection");
67+
c.drop();
68+
} catch (final ArangoDBException e) {
69+
}
70+
71+
try {
72+
ArangoCollection c = db.collection("view_replace_prop_test_collection");
73+
c.drop();
74+
} catch (final ArangoDBException e) {
75+
}
76+
6377
try {
6478
db.view(VIEW_NAME).drop();
6579
} catch (final ArangoDBException e) {
6680
}
6781
}
68-
82+
6983
@Test
7084
public void exists() {
7185
if (!requireVersion(3, 4)) {
@@ -200,6 +214,7 @@ public void replaceProperties() {
200214
if (!requireVersion(3, 4)) {
201215
return;
202216
}
217+
203218
db.createCollection("view_replace_prop_test_collection");
204219
final ArangoSearch view = db.arangoSearch(VIEW_NAME);
205220
view.create(new ArangoSearchCreateOptions());

src/test/java/com/arangodb/ArangoVertexCollectionTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,18 @@ public void setup() {
6868
} catch (final ArangoDBException e) {
6969
}
7070
final GraphCreateOptions options = new GraphCreateOptions().orphanCollections(COLLECTION_NAME);
71-
db.createGraph(GRAPH_NAME, null, options);
71+
try {
72+
db.createGraph(GRAPH_NAME, null, options);
73+
} catch (final ArangoDBException e) {
74+
}
75+
7276
}
7377

7478
@After
7579
public void teardown() {
76-
db.collection(COLLECTION_NAME).truncate();
80+
try {db.graph(GRAPH_NAME).drop();} catch (final ArangoDBException e) {}
81+
try {db.collection(COLLECTION_NAME).drop();} catch (final ArangoDBException e) {}
82+
7783
}
7884

7985
@Test

src/test/java/com/arangodb/BaseTest.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static Collection<ArangoDB.Builder> builders() {
4242
}
4343

4444
protected static final String TEST_DB = "java_driver_test_db";
45+
protected static final String TEST_DB_CUSTOM = "java_driver_test_db_custom";
4546
protected static ArangoDB arangoDB;
4647
protected static ArangoDatabase db;
4748

@@ -50,18 +51,21 @@ public BaseTest(final ArangoDB.Builder builder) {
5051
if (arangoDB != null) {
5152
shutdown();
5253
}
53-
arangoDB = builder.build();
54+
arangoDB = builder.build();
55+
db = arangoDB.db(TEST_DB);
56+
57+
// only create the database if not existing
5458
try {
55-
arangoDB.db(TEST_DB).drop();
59+
db.getVersion().getVersion();
5660
} catch (final ArangoDBException e) {
61+
if (e.getErrorNum() == 1228) { // DATABASE NOT FOUND
62+
arangoDB.createDatabase(TEST_DB);
63+
}
5764
}
58-
arangoDB.createDatabase(TEST_DB);
59-
db = arangoDB.db(TEST_DB);
6065
}
6166

6267
@AfterClass
6368
public static void shutdown() {
64-
arangoDB.db(TEST_DB).drop();
6569
arangoDB.shutdown();
6670
arangoDB = null;
6771
}

src/test/java/com/arangodb/DocumentTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public void setup() {
5858
@After
5959
public void teardown() {
6060
collection.truncate();
61+
try {
62+
db.collection(COLLECTION_NAME).drop();
63+
} catch (final ArangoDBException e) {
64+
65+
}
6166
}
6267

6368
@SuppressWarnings("unchecked")
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
arangodb.hosts=127.0.0.1:8529
22
arangodb.connections.max=1
3-
arangodb.acquireHostList=true
3+
arangodb.acquireHostList=false

0 commit comments

Comments
 (0)