[ 
https://issues.apache.org/jira/browse/FLINK-9962?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16569404#comment-16569404
 ] 

ASF GitHub Bot commented on FLINK-9962:
---------------------------------------

kl0u commented on a change in pull request #6492: [FLINK-9962] [FS connector] 
allow users to specify TimeZone in DateTimeBucketer
URL: https://github.com/apache/flink/pull/6492#discussion_r207728642
 
 

 ##########
 File path: 
flink-connectors/flink-connector-filesystem/src/test/java/org/apache/flink/streaming/connectors/fs/bucketing/DateTimeBucketerTest.java
 ##########
 @@ -0,0 +1,49 @@
+package org.apache.flink.streaming.connectors.fs.bucketing;
+
+import org.apache.flink.streaming.connectors.fs.Clock;
+
+import org.apache.hadoop.fs.Path;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.TimeZone;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+/**
+ * Tests for {@link DateTimeBucketer}.
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(DateTimeBucketer.class)
+public class DateTimeBucketerTest {
+       private static final long TEST_TIME_IN_MILLIS = 1533363082011L;
+       private static final Path TEST_PATH = new Path("test");
+
+       @Test
+       public void testGetBucketPathWithDefaultTimezone() {
+               TimeZone utc = TimeZone.getTimeZone("UTC");
+               PowerMockito.mockStatic(TimeZone.class);
+               when(TimeZone.getDefault()).thenReturn(utc);
+
+               DateTimeBucketer bucketer = new DateTimeBucketer();
+
+               Clock clock = mock(Clock.class);
+               when(clock.currentTimeMillis()).thenReturn(TEST_TIME_IN_MILLIS);
+
+               assertEquals(new Path("test/2018-08-04--06"), 
bucketer.getBucketPath(clock, TEST_PATH, null));
+       }
+
+       @Test
+       public void testGetBucketPathWithSpecifiedTimezone() {
+               Clock clock = mock(Clock.class);
+               when(clock.currentTimeMillis()).thenReturn(TEST_TIME_IN_MILLIS);
+               DateTimeBucketer bucketer = new 
DateTimeBucketer(TimeZone.getTimeZone("PST"));
+
+               assertEquals(new Path("test/2018-08-03--23"), 
bucketer.getBucketPath(clock, TEST_PATH, null));
+       }
+}
 
 Review comment:
   We do not need Powermock at all in these tests. We can remove all the mocks 
and add our own clock.
   ```
   new Clock() {
        @Override
        public long currentTimeMillis() {
                return TEST_TIME_IN_MILLIS;
        }
   }
   ```
   
   In general I am against mocking classes (if possible to avoid it) as this 
code maintainability more tricky.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> allow users to specify TimeZone in DateTimeBucketer
> ---------------------------------------------------
>
>                 Key: FLINK-9962
>                 URL: https://issues.apache.org/jira/browse/FLINK-9962
>             Project: Flink
>          Issue Type: Improvement
>          Components: Streaming Connectors
>    Affects Versions: 1.5.1, 1.6.0
>            Reporter: Bowen Li
>            Assignee: Bowen Li
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.7.0
>
>
> Currently {{DateTimeBucketer}} will return a bucket path by using local 
> timezone. We should add a {{timezone}} constructor param to allow users to 
> specify a timezone.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to