HDFS-13388. RequestHedgingProxyProvider calls multiple configured NNs all the time. Contributed by Jinglun.
This commit is contained in:
parent
821b0de4c5
commit
ac32b3576d
@ -79,6 +79,9 @@ public RequestHedgingInvocationHandler(
|
|||||||
public Object
|
public Object
|
||||||
invoke(Object proxy, final Method method, final Object[] args)
|
invoke(Object proxy, final Method method, final Object[] args)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
|
if (currentUsedProxy != null) {
|
||||||
|
return method.invoke(currentUsedProxy.proxy, args);
|
||||||
|
}
|
||||||
Map<Future<Object>, ProxyInfo<T>> proxyMap = new HashMap<>();
|
Map<Future<Object>, ProxyInfo<T>> proxyMap = new HashMap<>();
|
||||||
int numAttempts = 0;
|
int numAttempts = 0;
|
||||||
|
|
||||||
|
@ -43,10 +43,13 @@
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@ -99,6 +102,37 @@ public long[] answer(InvocationOnMock invocation) throws Throwable {
|
|||||||
Mockito.verify(goodMock).getStats();
|
Mockito.verify(goodMock).getStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRequestNNAfterOneSuccess() throws Exception {
|
||||||
|
final AtomicInteger count = new AtomicInteger(0);
|
||||||
|
final ClientProtocol goodMock = mock(ClientProtocol.class);
|
||||||
|
when(goodMock.getStats()).thenAnswer(new Answer<long[]>() {
|
||||||
|
@Override
|
||||||
|
public long[] answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
count.incrementAndGet();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
return new long[]{1};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final ClientProtocol badMock = mock(ClientProtocol.class);
|
||||||
|
when(badMock.getStats()).thenAnswer(new Answer<long[]>() {
|
||||||
|
@Override
|
||||||
|
public long[] answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
count.incrementAndGet();
|
||||||
|
throw new IOException("Bad mock !!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RequestHedgingProxyProvider<ClientProtocol> provider =
|
||||||
|
new RequestHedgingProxyProvider<>(conf, nnUri, ClientProtocol.class,
|
||||||
|
createFactory(badMock, goodMock, goodMock, badMock));
|
||||||
|
ClientProtocol proxy = provider.getProxy().proxy;
|
||||||
|
proxy.getStats();
|
||||||
|
assertEquals(2, count.get());
|
||||||
|
proxy.getStats();
|
||||||
|
assertEquals(3, count.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHedgingWhenOneIsSlow() throws Exception {
|
public void testHedgingWhenOneIsSlow() throws Exception {
|
||||||
final ClientProtocol goodMock = Mockito.mock(ClientProtocol.class);
|
final ClientProtocol goodMock = Mockito.mock(ClientProtocol.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user