24
24
25
25
import java .io .IOException ;
26
26
import java .time .Instant ;
27
+ import java .time .LocalDateTime ;
28
+ import java .time .ZoneId ;
27
29
import java .util .HashSet ;
28
30
import java .util .Set ;
29
31
@@ -58,6 +60,7 @@ public void setUp() {
58
60
MockitoAnnotations .initMocks (this );
59
61
this .sinkConfig = Mockito .mock (BlobSinkConfig .class );
60
62
Mockito .when (sinkConfig .getFilePartitionProtoTimestampTimezone ()).thenReturn (zone );
63
+ Mockito .when (sinkConfig .getFilePartitionProcessingTimeEnabled ()).thenReturn (false );
61
64
Mockito .when (sinkConfig .getOutputKafkaMetadataColumnName ()).thenReturn ("" );
62
65
Mockito .when (sinkConfig .getFilePartitionProtoTimestampFieldName ()).thenReturn (timeStampFieldName );
63
66
Mockito .when (sinkConfig .getFilePartitionTimeGranularityType ()).thenReturn (Constants .FilePartitionType .HOUR );
@@ -68,6 +71,7 @@ public void setUp() {
68
71
@ Test
69
72
public void shouldCreateLocalFileWriter () throws Exception {
70
73
Record record = Mockito .mock (Record .class );
74
+ Mockito .when (record .getLocalDateTime (sinkConfig )).thenReturn (LocalDateTime .now ());
71
75
Mockito .when (record .getTimestamp (timeStampFieldName )).thenReturn (Instant .ofEpochMilli (1L ));
72
76
Mockito .when (record .getTopic ("" )).thenReturn (defaultTopic );
73
77
Mockito .when (localFileWriter1 .getFullPath ()).thenReturn ("/tmp/test" );
@@ -82,13 +86,15 @@ public void shouldCreateLocalFileWriter() throws Exception {
82
86
@ Test
83
87
public void shouldCreateMultipleWriterBasedOnPartition () throws Exception {
84
88
Record record1 = Mockito .mock (Record .class );
89
+ Mockito .when (record1 .getLocalDateTime (sinkConfig )).thenReturn (LocalDateTime .ofInstant (Instant .ofEpochMilli (3600000L ), ZoneId .of (zone )));
85
90
Mockito .when (record1 .getTimestamp (timeStampFieldName )).thenReturn (Instant .ofEpochMilli (3600000L ));
86
91
Mockito .when (record1 .getTopic ("" )).thenReturn (defaultTopic );
87
92
Mockito .when (localStorage .createLocalFileWriter (TimePartitionedPathUtils .getTimePartitionedPath (record1 , sinkConfig ))).thenReturn (localFileWriter1 );
88
93
Mockito .when (localFileWriter1 .write (record1 )).thenReturn (true );
89
94
Mockito .when (localFileWriter1 .getFullPath ()).thenReturn ("/tmp/test1" );
90
95
91
96
Record record2 = Mockito .mock (Record .class );
97
+ Mockito .when (record2 .getLocalDateTime (sinkConfig )).thenReturn (LocalDateTime .ofInstant (Instant .ofEpochMilli (7200000L ), ZoneId .of (zone )));
92
98
Mockito .when (record2 .getTimestamp (timeStampFieldName )).thenReturn (Instant .ofEpochMilli (7200000L ));
93
99
Mockito .when (record2 .getTopic ("" )).thenReturn (defaultTopic );
94
100
Mockito .when (localStorage .createLocalFileWriter (TimePartitionedPathUtils .getTimePartitionedPath (record2 , sinkConfig ))).thenReturn (localFileWriter2 );
@@ -106,6 +112,7 @@ public void shouldCreateMultipleWriterBasedOnPartition() throws Exception {
106
112
@ Test (expected = IOException .class )
107
113
public void shouldThrowIOExceptionWhenWriteThrowsException () throws Exception {
108
114
Record record = Mockito .mock (Record .class );
115
+ Mockito .when (record .getLocalDateTime (sinkConfig )).thenReturn (LocalDateTime .now ());
109
116
Mockito .when (record .getTimestamp (timeStampFieldName )).thenReturn (Instant .ofEpochMilli (3600000L ));
110
117
Mockito .when (record .getTopic ("" )).thenReturn (defaultTopic );
111
118
Mockito .when (localFileWriter1 .getMetadata ()).thenReturn (new LocalFileMetadata ("/tmp/" , "/tmp/test1" , 0 , 0 , 0 ));
@@ -120,6 +127,7 @@ public void shouldThrowIOExceptionWhenWriteThrowsException() throws Exception {
120
127
public void shouldThrowIOExceptionWhenOpenNewWriterFailed () throws Exception {
121
128
expectedException .expect (LocalFileWriterFailedException .class );
122
129
Record record = Mockito .mock (Record .class );
130
+ Mockito .when (record .getLocalDateTime (sinkConfig )).thenReturn (LocalDateTime .now ());
123
131
Mockito .when (record .getTimestamp (timeStampFieldName )).thenReturn (Instant .ofEpochMilli (3600000L ));
124
132
Mockito .when (record .getTopic ("" )).thenReturn (defaultTopic );
125
133
Mockito .when (localFileWriter1 .getMetadata ()).thenReturn (new LocalFileMetadata ("/tmp/" , "/tmp/test1" , 0 , 0 , 0 ));
@@ -133,6 +141,7 @@ public void shouldThrowIOExceptionWhenOpenNewWriterFailed() throws Exception {
133
141
public void shouldGetEmptyFlushedPath () throws Exception {
134
142
Record record = Mockito .mock (Record .class );
135
143
Mockito .when (record .getTimestamp (timeStampFieldName )).thenReturn (Instant .ofEpochMilli (1L ));
144
+ Mockito .when (record .getLocalDateTime (sinkConfig )).thenReturn (LocalDateTime .ofInstant (Instant .ofEpochMilli (1L ), ZoneId .of (zone )));
136
145
Mockito .when (record .getTopic ("" )).thenReturn (defaultTopic );
137
146
Mockito .when (localFileWriter1 .getFullPath ()).thenReturn ("/tmp/test" );
138
147
Mockito .when (localStorage .createLocalFileWriter (TimePartitionedPathUtils .getTimePartitionedPath (record , sinkConfig ))).thenReturn (localFileWriter1 );
0 commit comments