Skip to content

Commit 0f04025

Browse files
authored
Merge pull request #679 from gjmwoods/4.0-increase-logging-on-it-tests
adding the ability to dump logs of local standalone and cluster neo4j…
2 parents 546cef1 + e9029cc commit 0f04025

11 files changed

+146
-1
lines changed

driver/src/test/java/org/neo4j/driver/stress/AbstractStressTestBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.jupiter.api.AfterEach;
2323
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
2526
import org.reactivestreams.Publisher;
2627
import reactor.core.publisher.Flux;
2728

@@ -88,6 +89,7 @@
8889
import static org.junit.jupiter.api.Assumptions.assumeTrue;
8990
import static org.neo4j.driver.SessionConfig.builder;
9091

92+
@ExtendWith( DumpLogsOnFailureWatcher.class )
9193
abstract class AbstractStressTestBase<C extends AbstractContext>
9294
{
9395
private static final int THREAD_COUNT = Integer.getInteger( "threadCount", 8 );
@@ -209,6 +211,8 @@ private void runStressTest( Function<C,List<Future<?>>> threadLauncher ) throws
209211
verifyResults( context, resourcesInfo );
210212
}
211213

214+
abstract void dumpLogs();
215+
212216
abstract URI databaseUri();
213217

214218
abstract AuthToken authToken();

driver/src/test/java/org/neo4j/driver/stress/CausalClusteringStressIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ void printStats( Context context )
128128
System.out.println( "Bookmark failures: " + context.getBookmarkFailures() );
129129
}
130130

131+
@Override
132+
void dumpLogs()
133+
{
134+
clusterRule.dumpClusterLogs();
135+
}
136+
131137
private static ClusterAddresses fetchClusterAddresses( Driver driver )
132138
{
133139
Set<String> followers = new HashSet<>();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2002-2020 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.stress;
20+
21+
import org.junit.jupiter.api.extension.ExtensionContext;
22+
import org.junit.jupiter.api.extension.TestWatcher;
23+
24+
import java.util.Optional;
25+
26+
public class DumpLogsOnFailureWatcher implements TestWatcher
27+
{
28+
@Override
29+
public void testDisabled( ExtensionContext context, Optional<String> reason )
30+
{
31+
// do nothing
32+
}
33+
34+
@Override
35+
public void testSuccessful( ExtensionContext context )
36+
{
37+
// do nothing
38+
}
39+
40+
@Override
41+
public void testAborted( ExtensionContext context, Throwable cause )
42+
{
43+
// do nothing
44+
}
45+
46+
@Override
47+
public void testFailed( ExtensionContext context, Throwable cause )
48+
{
49+
if ( context.getTestInstance().isPresent() && context.getTestInstance().get() instanceof AbstractStressTestBase<?>)
50+
{
51+
AbstractStressTestBase<?> clusterTest = (AbstractStressTestBase<?>) context.getTestInstance().get();
52+
clusterTest.dumpLogs();
53+
}
54+
}
55+
}

driver/src/test/java/org/neo4j/driver/stress/RxWriteQuery.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.neo4j.driver.reactive.RxSession;
3131

3232
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertFalse;
3334

3435
public class RxWriteQuery<C extends AbstractContext> extends AbstractRxQuery<C>
3536
{

driver/src/test/java/org/neo4j/driver/stress/RxWriteQueryWithRetries.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.neo4j.driver.reactive.RxSession;
3131

3232
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertFalse;
34+
import static org.junit.jupiter.api.Assertions.assertTrue;
3335

3436
public class RxWriteQueryWithRetries<C extends AbstractContext> extends AbstractRxQuery<C>
3537
{
@@ -45,7 +47,7 @@ public RxWriteQueryWithRetries( AbstractStressTestBase<C> stressTest, Driver dri
4547
public CompletionStage<Void> execute( C context )
4648
{
4749
CompletableFuture<Void> queryFinished = new CompletableFuture<>();
48-
Flux.usingWhen( Mono.fromSupplier( () -> newSession( AccessMode.READ, context ) ),
50+
Flux.usingWhen( Mono.fromSupplier( () -> newSession( AccessMode.WRITE, context ) ),
4951
session -> session.writeTransaction( tx -> tx.run( "CREATE ()" ).consume() ), RxSession::close )
5052
.subscribe( summary -> {
5153
queryFinished.complete( null );

driver/src/test/java/org/neo4j/driver/stress/SingleInstanceStressIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@ long getReadQueryCount()
114114
return readQueries.get();
115115
}
116116
}
117+
118+
@Override
119+
void dumpLogs()
120+
{
121+
neo4j.dumpLogs();
122+
}
117123
}

driver/src/test/java/org/neo4j/driver/util/DatabaseExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,9 @@ public ServerVersion version()
173173
{
174174
return ServerVersion.version( driver() );
175175
}
176+
177+
public void dumpLogs()
178+
{
179+
runner.dumpDebugLog();
180+
}
176181
}

driver/src/test/java/org/neo4j/driver/util/Neo4jRunner.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
package org.neo4j.driver.util;
2020

2121
import java.io.File;
22+
import java.io.FileNotFoundException;
2223
import java.io.IOException;
2324
import java.net.StandardSocketOptions;
2425
import java.net.URI;
2526
import java.nio.channels.SocketChannel;
2627
import java.util.ArrayList;
2728
import java.util.List;
2829
import java.util.Map;
30+
import java.util.Scanner;
2931

3032
import org.neo4j.driver.AuthToken;
3133
import org.neo4j.driver.Config;
@@ -240,6 +242,29 @@ public void restartNeo4j( Neo4jSettings neo4jSettings )
240242
}
241243
}
242244

245+
/**
246+
* prints the debug log contents to stdOut
247+
*/
248+
public void dumpDebugLog()
249+
{
250+
try
251+
{
252+
System.out.println( "Debug log for: " + HOME_DIR );
253+
Scanner input = new Scanner( new File( HOME_DIR + "/logs/debug.log" ));
254+
255+
while (input.hasNextLine())
256+
{
257+
System.out.println(input.nextLine());
258+
}
259+
}
260+
catch ( FileNotFoundException e )
261+
{
262+
System.out.println("Unable to find debug log file for: " + HOME_DIR);
263+
e.printStackTrace();
264+
}
265+
266+
}
267+
243268
private enum ServerStatus
244269
{
245270
ONLINE, OFFLINE

driver/src/test/java/org/neo4j/driver/util/cc/Cluster.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.neo4j.driver.util.cc;
2020

21+
import java.io.FileNotFoundException;
2122
import java.net.URI;
2223
import java.net.UnknownHostException;
2324
import java.nio.file.Path;
@@ -175,6 +176,24 @@ public Driver getDirectDriver( ClusterMember member )
175176
return clusterDrivers.getDriver( member );
176177
}
177178

179+
public void dumpClusterDebugLog()
180+
{
181+
for ( ClusterMember member : members )
182+
{
183+
184+
System.out.println( "Debug log for: " + member.getPath().toString() );
185+
try
186+
{
187+
member.dumpDebugLog();
188+
}
189+
catch ( FileNotFoundException e )
190+
{
191+
System.out.println("Unable to find debug log file for: " + member.getPath().toString());
192+
e.printStackTrace();
193+
}
194+
}
195+
}
196+
178197
@Override
179198
public void close()
180199
{

driver/src/test/java/org/neo4j/driver/util/cc/ClusterMember.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
*/
1919
package org.neo4j.driver.util.cc;
2020

21+
import java.io.File;
22+
import java.io.FileNotFoundException;
2123
import java.net.URI;
2224
import java.net.UnknownHostException;
2325
import java.nio.file.Path;
2426
import java.util.Objects;
27+
import java.util.Scanner;
2528

2629
import org.neo4j.driver.internal.BoltServerAddress;
2730

@@ -63,6 +66,16 @@ public Path getPath()
6366
return path;
6467
}
6568

69+
public void dumpDebugLog() throws FileNotFoundException
70+
{
71+
Scanner input = new Scanner( new File( path.toAbsolutePath().toString() + "/logs/debug.log" ));
72+
73+
while (input.hasNextLine())
74+
{
75+
System.out.println(input.nextLine());
76+
}
77+
}
78+
6679
@Override
6780
public boolean equals( Object o )
6881
{

driver/src/test/java/org/neo4j/driver/util/cc/LocalOrRemoteClusterExtension.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.jupiter.api.extension.BeforeAllCallback;
2424
import org.junit.jupiter.api.extension.ExtensionContext;
2525

26+
import java.io.FileNotFoundException;
2627
import java.net.URI;
2728

2829
import org.neo4j.driver.internal.util.DriverFactoryWithOneEventLoopThread;
@@ -99,6 +100,14 @@ public void afterAll( ExtensionContext context )
99100
}
100101
}
101102

103+
public void dumpClusterLogs()
104+
{
105+
if ( localClusterExtension != null )
106+
{
107+
localClusterExtension.getCluster().dumpClusterDebugLog();
108+
}
109+
}
110+
102111
private void deleteDataInRemoteCluster()
103112
{
104113
DriverFactoryWithOneEventLoopThread driverFactory = new DriverFactoryWithOneEventLoopThread();

0 commit comments

Comments
 (0)