Github user benchristel commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1379#discussion_r201876799
  
    --- Diff: 
pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/UGICacheTest.java ---
    @@ -0,0 +1,197 @@
    +package org.apache.hawq.pxf.service;
    +
    +import org.apache.hadoop.security.UserGroupInformation;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.mockito.stubbing.Answer;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertNotEquals;
    +import static org.junit.Assert.assertNotNull;
    +import static org.mockito.Matchers.any;
    +import static org.mockito.Mockito.*;
    +import static org.powermock.api.mockito.PowerMockito.when;
    +
    +public class UGICacheTest {
    +    private UGIProvider provider = null;
    +    private SessionId session = null;
    +    private UGICache cache = null;
    +
    +    @Before
    +    public void setUp() throws Exception {
    +        provider = mock(UGIProvider.class);
    +
    +        
when(provider.createProxyUGI(any(String.class))).thenAnswer((Answer<UserGroupInformation>)
 invocation -> mock(UserGroupInformation.class));
    +
    +        session = new SessionId(0, "txn-id", "the-user");
    +
    +        cache = new UGICache(provider);
    +    }
    +
    +    @Test
    +    public void getUGIFromEmptyCache() throws Exception {
    +        UGICacheEntry entry = cache.getTimedProxyUGI(session);
    +        assertNotNull(entry.getUGI());
    +        verify(provider).createProxyUGI("the-user");
    --- End diff --
    
    The ref count and expiration time are internal details of the cache, so 
rather than directly test them, we have other tests that simulate time passing, 
acquire multiple references etc. and assert that the UGIs are destroyed at the 
right time.
    
    I believe the mock verification 
`verify(provider).createProxyUGI("the-user")` is as close as we can get to 
verifying the principals of the UGI, because we're using a mock UGI here.


---

Reply via email to