bitflicker64 commented on code in PR #805: URL: https://github.com/apache/hugegraph-toolchain/pull/805#discussion_r4286344352
########## hugegraph-hubble/hubble-be/src/test/java/org/apache/hugegraph/unit/HubbleUtilTest.java: ########## @@ -0,0 +1,125 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package org.apache.hugegraph.unit; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.hugegraph.testutil.Assert; +import org.apache.hugegraph.util.HubbleUtil; +import org.apache.hugegraph.util.SerializeUtil; +import org.junit.Test; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +public class HubbleUtilTest { + + @Test + public void testEqualCollection() { + Assert.assertTrue(HubbleUtil.equalCollection(null, null)); + Assert.assertTrue(HubbleUtil.equalCollection(Arrays.asList("a", "b"), + Arrays.asList("b", "a"))); + Assert.assertTrue(HubbleUtil.equalCollection(Collections.emptyList(), + Collections.emptySet())); + Assert.assertFalse(HubbleUtil.equalCollection(Arrays.asList("a"), null)); + Assert.assertFalse(HubbleUtil.equalCollection(null, Arrays.asList("a"))); + Assert.assertFalse(HubbleUtil.equalCollection(Arrays.asList("a", "a"), + Arrays.asList("a"))); + Assert.assertFalse(HubbleUtil.equalCollection(Arrays.asList("a"), + Arrays.asList("b"))); + } + + @Test + public void testTimestampsBefore24Hours() { + long[] timestamps = HubbleUtil.getTimestampsBefore24Hours("20240115 12:00:00"); + + // 2024-01-15 12:00:00 is parsed in the default time zone + long offset = TimeZone.getDefault().getOffset(1705320000000L) / 1000L; + long expected = 1705320000L - offset; + Assert.assertArrayEquals(new long[]{expected - 86400L, expected}, timestamps); + + long[] now = HubbleUtil.getTimestampsBefore24Hours(); + Assert.assertEquals(86400L, now[1] - now[0]); + + Assert.assertThrows(RuntimeException.class, () -> { + HubbleUtil.getTimestampsBefore24Hours("2024-01-15 12:00:00"); + }, e -> { + Assert.assertTrue(e.getCause() instanceof java.text.ParseException); + }); + } + + @Test + public void testDateFormatDay() { + Assert.assertEquals("2024-01-15", HubbleUtil.dateFormatDay("20240115")); + Assert.assertEquals("20240115", HubbleUtil.dateFormatDay(new Date(1705291200000L))); Review Comment: Important: this assertion only passes in time zones at UTC-4 or further east. `HubbleUtil.dateFormatDay(Date)` is `new SimpleDateFormat("yyyyMMdd").format(date)`, so it formats in the JVM default zone, and `1705291200000L` is 2024-01-15T04:00:00Z. That instant is still 14 January in New York, Los Angeles or Honolulu, so `mvn test -P unit-test` in hubble-be fails for a contributor there. CI passes only because the GitHub runners use UTC, and the hubble-be surefire config does not pin `user.timezone`. Evidence: the same call, run with `java -Duser.timezone=<zone>`: ``` UTC day=20240115 month=202401 Asia/Shanghai day=20240115 month=202401 America/Sao_Paulo day=20240115 month=202401 America/New_York day=20240114 month=202401 America/Los_Angeles day=20240114 month=202401 Pacific/Honolulu day=20240114 month=202401 ``` `testTimestampsBefore24Hours` in the same class already handles this by computing the offset from `TimeZone.getDefault()`. Requested change: build the date from local calendar fields so it is 15 January in every zone, for example `Date day = new GregorianCalendar(2024, Calendar.JANUARY, 15, 12, 0).getTime();`, and use it for both the `dateFormatDay` and `dateFormatMonth` assertions on lines 73 and 74. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
