Skip to content

Commit 21dbe89

Browse files
njain2208njain34
authored and
njain34
committed
flaky fixes in the project
1 parent 09895c1 commit 21dbe89

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/test/java/com/zavtech/morpheus/array/ArrayBuilderTests.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.Month;
2222
import java.time.ZoneId;
2323
import java.time.ZonedDateTime;
24+
import java.time.temporal.ChronoUnit;
2425
import java.util.Calendar;
2526
import java.util.Currency;
2627
import java.util.Date;
@@ -349,11 +350,11 @@ public void testWithLocalDateTimes(int initialSize) {
349350
Assert.assertEquals(actual.length(), expected.length, "The lengths match");
350351
Assert.assertEquals(actual.typeCode(), ArrayType.LOCAL_DATETIME, "The array type is as expected");
351352
for (int i=0; i<expected.length; ++i) {
352-
Assert.assertEquals(actual.getValue(i), expected[i], "The values match at " + i);
353+
Assert.assertEquals(actual.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
353354
}
354355
final Array<LocalDateTime> collected = Stream.of(expected).collect(ArrayUtils.toArray(expected.length));
355356
for (int i=0; i<expected.length; ++i) {
356-
Assert.assertEquals(collected.getValue(i), expected[i], "The values match at " + i);
357+
Assert.assertEquals(collected.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
357358
}
358359
}
359360

@@ -370,11 +371,11 @@ public void testWithZonedDateTimes(int initialSize) {
370371
Assert.assertEquals(actual.length(), expected.length, "The lengths match");
371372
Assert.assertEquals(actual.typeCode(), ArrayType.ZONED_DATETIME, "The array type is as expected");
372373
for (int i=0; i<expected.length; ++i) {
373-
Assert.assertEquals(actual.getValue(i), expected[i], "The values match at " + i);
374+
Assert.assertEquals(actual.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
374375
}
375376
final Array<ZonedDateTime> collected = Stream.of(expected).collect(ArrayUtils.toArray(expected.length));
376377
for (int i=0; i<expected.length; ++i) {
377-
Assert.assertEquals(collected.getValue(i), expected[i], "The values match at " + i);
378+
Assert.assertEquals(collected.getValue(i), expected[i].truncatedTo(ChronoUnit.MILLIS), "The values match at " + i);
378379
}
379380
}
380381

@@ -408,11 +409,19 @@ public void testWithMixedTypes(int initialSize) {
408409
Assert.assertEquals(actual.length(), expected.length, "The lengths match");
409410
Assert.assertEquals(actual.typeCode(), ArrayType.OBJECT, "The array type is as expected");
410411
for (int i=0; i<expected.length; ++i) {
411-
Assert.assertEquals(actual.getValue(i), expected[i], "The values match at " + i);
412+
Object frmtValue = expected[i];
413+
if(expected[i].getClass().getName() == "java.time.ZonedDateTime"){
414+
frmtValue = ((ZonedDateTime) frmtValue).truncatedTo(ChronoUnit.MILLIS);
415+
}
416+
Assert.assertEquals(actual.getValue(i),frmtValue, "The values match at " + i);
412417
}
413418
final Array<Object> collected = Stream.of(expected).collect(ArrayUtils.toArray(expected.length));
414419
for (int i=0; i<expected.length; ++i) {
415-
Assert.assertEquals(collected.getValue(i), expected[i], "The values match at " + i);
420+
Object frmtValue = expected[i];
421+
if(expected[i].getClass().getName() == "java.time.ZonedDateTime"){
422+
frmtValue = ((ZonedDateTime) frmtValue).truncatedTo(ChronoUnit.MILLIS);
423+
}
424+
Assert.assertEquals(collected.getValue(i), frmtValue, "The values match at " + i);
416425
}
417426
}
418427

src/test/java/com/zavtech/morpheus/array/ArrayMappedTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.ZoneId;
2020
import java.time.ZonedDateTime;
21+
import java.time.temporal.ChronoUnit;
2122
import java.util.Random;
2223

2324
import org.testng.Assert;
@@ -92,8 +93,8 @@ public void testZonedDateTime() {
9293
array2[i] = value;
9394
}
9495
for (int i=0; i<count; ++i) {
95-
final ZonedDateTime v1 = array1.getValue(i);
96-
final ZonedDateTime v2 = array2[i];
96+
final ZonedDateTime v1 = array1.getValue(i).truncatedTo(ChronoUnit.MILLIS);
97+
final ZonedDateTime v2 = array2[i].truncatedTo(ChronoUnit.MILLIS);
9798
Assert.assertEquals(v1, v2);
9899
System.out.println(v1);
99100
}

src/test/java/com/zavtech/morpheus/array/ArraysBasicTests.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.Month;
2222
import java.time.ZoneId;
2323
import java.time.ZonedDateTime;
24+
import java.time.temporal.ChronoUnit;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
2627
import java.util.Currency;
@@ -604,14 +605,14 @@ public void testLocalDateTimeArray(boolean sparse) {
604605
array.setValue(i, value);
605606
}
606607
for (int i=0; i<values.length; ++i) {
607-
final LocalDateTime v1 = values[i];
608+
final LocalDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
608609
final LocalDateTime v2 = array.getValue(i);
609610
Assert.assertEquals(v1, v2, "Values match at " + i);
610611
}
611612
array.expand(200);
612613
Assert.assertEquals(array.length(), 200, "The array was expanded");
613614
for (int i=0; i<values.length; ++i) {
614-
final LocalDateTime v1 = values[i];
615+
final LocalDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
615616
final LocalDateTime v2 = array.getValue(i);
616617
Assert.assertEquals(v1, v2, "Values match at " + i);
617618
}
@@ -625,7 +626,7 @@ public void testLocalDateTimeArray(boolean sparse) {
625626
array.setValue(i, value);
626627
}
627628
for (int i=100; i<200; ++i) {
628-
final LocalDateTime v1 = values[i-100];
629+
final LocalDateTime v1 = values[i-100].truncatedTo(ChronoUnit.MILLIS);
629630
final LocalDateTime v2 = array.getValue(i);
630631
Assert.assertEquals(v1, v2, "Values match at " + i);
631632
}
@@ -650,14 +651,14 @@ public void testZonedDateTimeArray(boolean sparse) {
650651
array.setValue(i, value);
651652
}
652653
for (int i=0; i<values.length; ++i) {
653-
final ZonedDateTime v1 = values[i];
654+
final ZonedDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
654655
final ZonedDateTime v2 = array.getValue(i);
655656
Assert.assertEquals(v1, v2, "Values match at " + i);
656657
}
657658
array.expand(200);
658659
Assert.assertEquals(array.length(), 200, "The array was expanded");
659660
for (int i=0; i<values.length; ++i) {
660-
final ZonedDateTime v1 = values[i];
661+
final ZonedDateTime v1 = values[i].truncatedTo(ChronoUnit.MILLIS);
661662
final ZonedDateTime v2 = array.getValue(i);
662663
Assert.assertEquals(v1, v2, "Values match at " + i);
663664
}
@@ -672,7 +673,7 @@ public void testZonedDateTimeArray(boolean sparse) {
672673
array.setValue(i, value);
673674
}
674675
for (int i=100; i<200; ++i) {
675-
final ZonedDateTime v1 = values[i-100];
676+
final ZonedDateTime v1 = values[i-100].truncatedTo(ChronoUnit.MILLIS);
676677
final ZonedDateTime v2 = array.getValue(i);
677678
Assert.assertEquals(v1, v2, "Values match at " + i);
678679
}
@@ -818,13 +819,15 @@ public <T> void testFill(Class<T> type, ArrayStyle style) {
818819
T value = (T)LocalDateTime.now();
819820
array.fill(value);
820821
for (int i=0; i<array.length(); ++i) {
821-
Assert.assertEquals(array.getValue(i), value, "Values match at " + i);
822+
LocalDateTime formattedValue = ((LocalDateTime) value).truncatedTo(ChronoUnit.MILLIS);
823+
Assert.assertEquals(array.getValue(i), formattedValue, "Values match at " + i);
822824
}
823825
} else if (array.typeCode() == ArrayType.ZONED_DATETIME) {
824826
T value = (T)ZonedDateTime.now();
825827
array.fill(value);
826828
for (int i=0; i<array.length(); ++i) {
827-
Assert.assertEquals(array.getValue(i), value, "Values match at " + i);
829+
ZonedDateTime formattedValue = ((ZonedDateTime) value).truncatedTo(ChronoUnit.MILLIS);
830+
Assert.assertEquals(array.getValue(i), formattedValue, "Values match at " + i);
828831
}
829832
} else if (array.typeCode() == ArrayType.OBJECT) {
830833
T value = (T)new Double(7d);
@@ -968,12 +971,12 @@ public <T> void testFirstAndLast(Class<T> type, ArrayStyle style) {
968971
assertFirstAndLast(array, values, arrayType);
969972
} else if (arrayType == ArrayType.LOCAL_DATETIME) {
970973
final LocalDateTime[] values = new LocalDateTime[1000];
971-
for (int i=0; i<values.length; ++i) values[i] = LocalDateTime.now().plusSeconds(i);
974+
for (int i=0; i<values.length; ++i) values[i] = LocalDateTime.now().plusSeconds(i).truncatedTo(ChronoUnit.MILLIS);
972975
final Array<LocalDateTime> array = Array.of((Class<LocalDateTime>)type, values.length, null, style).applyValues(v -> values[v.index()]);
973976
assertFirstAndLast(array, values, arrayType);
974977
} else if (arrayType == ArrayType.ZONED_DATETIME) {
975978
final ZonedDateTime[] values = new ZonedDateTime[1000];
976-
for (int i=0; i<values.length; ++i) values[i] = ZonedDateTime.now().plusSeconds(i);
979+
for (int i=0; i<values.length; ++i) values[i] = ZonedDateTime.now().plusSeconds(i).truncatedTo(ChronoUnit.MILLIS);
977980
final Array<ZonedDateTime> array = Array.of((Class<ZonedDateTime>)type, values.length, null, style).applyValues(v -> values[v.index()]);
978981
assertFirstAndLast(array, values, arrayType);
979982
} else if (arrayType == ArrayType.OBJECT) {

0 commit comments

Comments
 (0)