Github user denalex commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/1379#discussion_r201523243 --- 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"); + } + + @Test + public void getSameUGITwiceUsesCache() throws Exception { + UGICacheEntry entry1 = cache.getTimedProxyUGI(session); + UGICacheEntry entry2 = cache.getTimedProxyUGI(session); + assertEquals(entry1, entry2); --- End diff -- assertSame for ref comparison ?
---