Skip to content

Commit 2a21e5f

Browse files
committed
Fix random zone id generation to skip some ids
`Canada/East-Saskatchewan` was removed from the tz database and neo4j will return `Canada/Saskatchewan` instead. This caused some random assertion failures.
1 parent b33d284 commit 2a21e5f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.ZonedDateTime;
2828
import java.time.temporal.ChronoField;
2929
import java.time.temporal.ValueRange;
30+
import java.util.Collections;
3031
import java.util.Set;
3132
import java.util.concurrent.ThreadLocalRandom;
3233

@@ -40,9 +41,16 @@
4041
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
4142
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
4243
import static java.time.temporal.ChronoField.YEAR;
44+
import static java.util.stream.Collectors.toSet;
4345

4446
public final class TemporalUtil
4547
{
48+
/**
49+
* These zone ids were removed from the tz database and neo4j can re-map such ids to other ids.
50+
* For example "Canada/East-Saskatchewan" will be returned as "Canada/Saskatchewan".
51+
*/
52+
private static final Set<String> BLACKLISTED_ZONE_IDS = Collections.singleton( "Canada/East-Saskatchewan" );
53+
4654
private TemporalUtil()
4755
{
4856
}
@@ -100,7 +108,11 @@ private static ZoneOffset randomZoneOffset()
100108

101109
private static ZoneId randomZoneId()
102110
{
103-
Set<String> availableZoneIds = ZoneId.getAvailableZoneIds();
111+
Set<String> availableZoneIds = ZoneId.getAvailableZoneIds()
112+
.stream()
113+
.filter( id -> !BLACKLISTED_ZONE_IDS.contains( id ) )
114+
.collect( toSet() );
115+
104116
int randomIndex = random().nextInt( availableZoneIds.size() );
105117
int index = 0;
106118
for ( String id : availableZoneIds )

0 commit comments

Comments
 (0)