19
19
20
20
package org .apache .druid .server .lookup ;
21
21
22
- import com .amazonaws .transform .MapEntry ;
23
22
import com .google .common .collect .ImmutableMap ;
24
23
import com .google .common .collect .ImmutableSet ;
25
24
import org .apache .druid .common .config .NullHandling ;
31
30
import org .junit .Test ;
32
31
import org .junit .rules .ExpectedException ;
33
32
34
- import java .util .*;
33
+ import java .util .AbstractMap ;
34
+ import java .util .Arrays ;
35
+ import java .util .Collections ;
36
+ import java .util .Iterator ;
37
+ import java .util .Map ;
35
38
import java .util .concurrent .Callable ;
36
39
import java .util .concurrent .ExecutionException ;
37
40
@@ -48,7 +51,7 @@ public class LoadingLookupTest extends InitializedNullHandlingTest
48
51
@ Test
49
52
public void testApplyEmptyOrNull () throws ExecutionException
50
53
{
51
- EasyMock .expect (lookupCache .get (EasyMock .eq ("" ), EasyMock . anyObject ( Callable . class )))
54
+ EasyMock .expect (lookupCache .getIfPresent (EasyMock .eq ("" )))
52
55
.andReturn ("empty" ).atLeastOnce ();
53
56
EasyMock .replay (lookupCache );
54
57
Assert .assertEquals ("empty" , loadingLookup .apply ("" ));
@@ -74,7 +77,7 @@ public void testUnapplyNull()
74
77
@ Test
75
78
public void testApply () throws ExecutionException
76
79
{
77
- EasyMock .expect (lookupCache .get (EasyMock .eq ("key" ), EasyMock . anyObject ( Callable . class ))).andReturn ("value" ).once ();
80
+ EasyMock .expect (lookupCache .getIfPresent (EasyMock .eq ("key" ))).andReturn ("value" ).once ();
78
81
EasyMock .replay (lookupCache );
79
82
Assert .assertEquals (ImmutableMap .of ("key" , "value" ), loadingLookup .applyAll (ImmutableSet .of ("key" )));
80
83
EasyMock .verify (lookupCache );
@@ -101,17 +104,6 @@ public void testClose()
101
104
EasyMock .verify (lookupCache , reverseLookupCache );
102
105
}
103
106
104
- @ Test
105
- public void testApplyWithExecutionError () throws ExecutionException
106
- {
107
- EasyMock .expect (lookupCache .get (EasyMock .eq ("key" ), EasyMock .anyObject (Callable .class )))
108
- .andThrow (new ExecutionException (null ))
109
- .once ();
110
- EasyMock .replay (lookupCache );
111
- Assert .assertNull (loadingLookup .apply ("key" ));
112
- EasyMock .verify (lookupCache );
113
- }
114
-
115
107
@ Test
116
108
public void testUnApplyWithExecutionError () throws ExecutionException
117
109
{
@@ -161,9 +153,13 @@ public void testFetchAll()
161
153
EasyMock .verify (dataFetcher );
162
154
}
163
155
164
- public int getIteratorSize (Iterator <Map .Entry <String , String >> it ) {
165
- int i = 0 ;
166
- for ( ; it .hasNext () ; ++i ) it .next ();
167
- return i ;
156
+ public int getIteratorSize (Iterator <Map .Entry <String , String >> it )
157
+ {
158
+ int sum = 0 ;
159
+ while (it .hasNext ()) {
160
+ sum ++;
161
+ it .next ();
162
+ }
163
+ return sum ;
168
164
}
169
165
}
0 commit comments