Skip to content

Commit 92b6746

Browse files
author
Zhen Li
committed
Merge branch '1.7' into 2.0
2 parents aaf817e + 3a72fe4 commit 92b6746

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

driver/src/test/java/org/neo4j/driver/v1/util/CertificateExtension.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,51 @@
1818
*/
1919
package org.neo4j.driver.v1.util;
2020

21-
import org.junit.jupiter.api.extension.AfterAllCallback;
22-
import org.junit.jupiter.api.extension.BeforeAllCallback;
21+
import org.junit.jupiter.api.extension.AfterEachCallback;
2322
import org.junit.jupiter.api.extension.ExtensionContext;
2423

24+
import java.io.IOException;
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
2727
import java.nio.file.StandardCopyOption;
28+
import java.util.Arrays;
2829

29-
public class CertificateExtension extends DatabaseExtension implements BeforeAllCallback, AfterAllCallback
30+
import static org.neo4j.driver.v1.util.Neo4jRunner.debug;
31+
32+
public class CertificateExtension extends DatabaseExtension implements AfterEachCallback
3033
{
31-
private static Path originalKeyFile;
32-
private static Path originalCertFile;
34+
private Path originalKeyFile;
35+
private Path originalCertFile;
3336

3437
@Override
35-
public void beforeAll( ExtensionContext extensionContext ) throws Exception
38+
public void beforeEach( ExtensionContext context ) throws Exception
3639
{
40+
super.beforeEach( context );
41+
3742
originalKeyFile = Files.createTempFile( "key-file-", "" );
3843
originalCertFile = Files.createTempFile( "cert-file-", "" );
3944

40-
Files.copy( tlsKeyFile().toPath(), originalKeyFile , StandardCopyOption.REPLACE_EXISTING);
45+
Files.copy( tlsKeyFile().toPath(), originalKeyFile, StandardCopyOption.REPLACE_EXISTING );
4146
Files.copy( tlsCertFile().toPath(), originalCertFile, StandardCopyOption.REPLACE_EXISTING );
4247
}
4348

4449
@Override
45-
public void afterAll( ExtensionContext extensionContext ) throws Exception
50+
public void afterEach( ExtensionContext context ) throws Exception
4651
{
47-
updateEncryptionKeyAndCert( originalKeyFile.toFile(), originalCertFile.toFile() );
52+
// if the key and cert file changed, then we restore the file and restart the server.
53+
if ( !smallFileContentEquals( tlsKeyFile().toPath(), originalKeyFile ) || !smallFileContentEquals( tlsCertFile().toPath(), originalCertFile ) )
54+
{
55+
debug( "Restoring original key and certificate file after certificate test." );
56+
updateEncryptionKeyAndCert( originalKeyFile.toFile(), originalCertFile.toFile() );
57+
}
4858
Files.deleteIfExists( originalKeyFile );
4959
Files.deleteIfExists( originalCertFile );
5060
}
61+
62+
private boolean smallFileContentEquals( Path path, Path pathAnother ) throws IOException
63+
{
64+
byte[] fileContent = Files.readAllBytes( path );
65+
byte[] fileContentAnother = Files.readAllBytes( pathAnother );
66+
return Arrays.equals( fileContent, fileContentAnother );
67+
}
5168
}

driver/src/test/java/org/neo4j/driver/v1/util/TemporalUtil.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import java.time.ZonedDateTime;
2929
import java.time.temporal.ChronoField;
3030
import java.time.temporal.ValueRange;
31+
import java.util.Arrays;
3132
import java.util.Collections;
33+
import java.util.List;
3234
import java.util.Set;
3335
import java.util.concurrent.ThreadLocalRandom;
3436

@@ -47,10 +49,18 @@
4749
public final class TemporalUtil
4850
{
4951
/**
50-
* These zone ids were removed from the tz database and neo4j can re-map such ids to other ids.
52+
* A list of zone ids whose use might lead to unexpected results.
53+
* <p>
54+
* Some ids were removed from the tz database and neo4j can re-map such ids to other ids.
5155
* For example "Canada/East-Saskatchewan" will be returned as "Canada/Saskatchewan".
56+
* Other time zones are not working correctly in some Java versions
5257
*/
53-
private static final Set<String> BLACKLISTED_ZONE_IDS = Collections.singleton( "Canada/East-Saskatchewan" );
58+
private static final List<String> BLACKLISTED_ZONE_IDS = Arrays.asList(
59+
// removed
60+
"Canada/East-Saskatchewan",
61+
// is broken for years in distant future in Java 11 (example of a misbehaving date: +71235332-08-09T22:41:50.738292551-06:00[Chile/EasterIsland])
62+
"Chile/EasterIsland"
63+
);
5464

5565
private TemporalUtil()
5666
{

0 commit comments

Comments
 (0)