hawq-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denalex <...@git.apache.org>
Subject [GitHub] incubator-hawq pull request #1379: HAWQ-1622. Cache PXF proxy UGI so that cl...
Date Tue, 10 Jul 2018 23:24:00 GMT
Github user denalex commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/1379#discussion_r201523938
  
    --- 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);
    +        assertNotNull(entry1.getUGI());
    +        verify(provider, times(1)).createProxyUGI("the-user");
    +    }
    +
    +    @Test
    +    public void getTwoUGIsWithDifferentSessionsForSameUser() throws Exception {
    +        SessionId otherSession = new SessionId(0, "txn-id-2", "the-user");
    +        UGICacheEntry proxyUGI1 = cache.getTimedProxyUGI(session);
    +        UGICacheEntry proxyUGI2 = cache.getTimedProxyUGI(otherSession);
    +        assertNotEquals(proxyUGI1, proxyUGI2);
    +        verify(provider, times(2)).createProxyUGI("the-user");
    +        // TODO: this seems weird. We're creating two UGIs with the same params,
    +        // even though we have two different sessions. Why?
    +    }
    +
    +    @Test
    +    public void getTwoUGIsWithDifferentUsers() throws Exception {
    +        SessionId otherSession = new SessionId(0, "txn-id", "different-user");
    +        UGICacheEntry proxyUGI1 = cache.getTimedProxyUGI(session);
    +        UGICacheEntry proxyUGI2 = cache.getTimedProxyUGI(otherSession);
    +        assertNotEquals(proxyUGI1, proxyUGI2);
    +        verify(provider, times(1)).createProxyUGI("the-user");
    +        verify(provider, times(1)).createProxyUGI("different-user");
    +    }
    +
    +    @Test
    +    public void getTwoUGIsWithDifferentUsersCachesBoth() throws Exception {
    +        SessionId otherSession = new SessionId(0, "txn-id", "different-user");
    +        UGICacheEntry proxyUGI1a = cache.getTimedProxyUGI(session);
    +        UGICacheEntry proxyUGI1b = cache.getTimedProxyUGI(session);
    +        UGICacheEntry proxyUGI2a = cache.getTimedProxyUGI(otherSession);
    +        UGICacheEntry proxyUGI2b = cache.getTimedProxyUGI(otherSession);
    +        assertEquals(proxyUGI1a, proxyUGI1b);
    +        assertEquals(proxyUGI2a, proxyUGI2b);
    +        assertNotEquals(proxyUGI1a, proxyUGI2a);
    +        verify(provider, times(1)).createProxyUGI("the-user");
    +        verify(provider, times(1)).createProxyUGI("different-user");
    +    }
    +
    +    @Test
    +    public void getUGIWhenRequestedUserDoesNotExist() throws Exception {
    +        // what does UserGroupInformation.createProxyUser() do in this scenario?
    +        // how about getLoginUser()?
    +    }
    +
    +    @Test
    +    public void anySegmentIdIsValid() throws Exception {
    +        session = new SessionId(65, "txn-id", "the-user");
    --- End diff --
    
    is this relevant anymore since magic number 64 is gone now ?


---

Mime
View raw message