-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[producer][samza] Reinitalize transport client if a store has moved (#…
…844) * [producer][samza] Reinitalize transport client if a store has moved (resulting in store not found errors) This is to allow store moves to not break system producers.
- Loading branch information
Showing
3 changed files
with
162 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...src/test/java/com/linkedin/venice/pushmonitor/RouterBasedHybridStoreQuotaMonitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.linkedin.venice.pushmonitor; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.linkedin.venice.client.store.transport.TransportClient; | ||
import com.linkedin.venice.client.store.transport.TransportClientResponse; | ||
import com.linkedin.venice.exceptions.ErrorType; | ||
import com.linkedin.venice.meta.Version; | ||
import com.linkedin.venice.routerapi.HybridStoreQuotaStatusResponse; | ||
import java.io.IOException; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
import org.mockito.Mockito; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class RouterBasedHybridStoreQuotaMonitorTest { | ||
private static final String STORE_NAME = "fake_Store"; | ||
private static final String TOPIC_NAME = "fake_Store_v1"; | ||
|
||
@Test | ||
public void testTransportClientReinit() | ||
throws IOException, ExecutionException, InterruptedException, TimeoutException { | ||
TransportClient mockTransportclient = Mockito.mock(TransportClient.class); | ||
TransportClientResponse mockResponse = Mockito.mock(TransportClientResponse.class); | ||
ObjectMapper mockMapper = Mockito.mock(ObjectMapper.class); | ||
HybridStoreQuotaStatusResponse mockQuotaStatusResponse = Mockito.mock(HybridStoreQuotaStatusResponse.class); | ||
Mockito.when(mockResponse.getBody()).thenReturn(STORE_NAME.getBytes()); | ||
Mockito.when(mockTransportclient.get(Mockito.anyString())) | ||
.thenReturn(CompletableFuture.completedFuture(mockResponse)); | ||
Mockito | ||
.when(mockMapper.readValue(Mockito.eq(STORE_NAME.getBytes()), Mockito.eq(HybridStoreQuotaStatusResponse.class))) | ||
.thenReturn(mockQuotaStatusResponse); | ||
Mockito.when(mockQuotaStatusResponse.isError()).thenReturn(true); | ||
Mockito.when(mockQuotaStatusResponse.getErrorType()).thenReturn(ErrorType.STORE_NOT_FOUND); | ||
|
||
final boolean[] isReinitCalled = { false }; | ||
RouterBasedHybridStoreQuotaMonitor.TransportClientReinitProvider transportClientReinitProvider = () -> { | ||
isReinitCalled[0] = true; | ||
return mockTransportclient; | ||
}; | ||
RouterBasedHybridStoreQuotaMonitor routerBasedHybridStoreQuotaMonitor = new RouterBasedHybridStoreQuotaMonitor( | ||
mockTransportclient, | ||
STORE_NAME, | ||
Version.PushType.STREAM, | ||
TOPIC_NAME, | ||
transportClientReinitProvider); | ||
|
||
routerBasedHybridStoreQuotaMonitor.getHybridQuotaMonitorTask().setMapper(mockMapper); | ||
routerBasedHybridStoreQuotaMonitor.getHybridQuotaMonitorTask().checkStatus(); | ||
|
||
Assert.assertTrue(isReinitCalled[0]); | ||
} | ||
|
||
@Test | ||
public void testStatusChange() throws IOException, ExecutionException, InterruptedException, TimeoutException { | ||
TransportClient mockTransportclient = Mockito.mock(TransportClient.class); | ||
TransportClientResponse mockResponse = Mockito.mock(TransportClientResponse.class); | ||
ObjectMapper mockMapper = Mockito.mock(ObjectMapper.class); | ||
HybridStoreQuotaStatusResponse mockQuotaStatusResponse = Mockito.mock(HybridStoreQuotaStatusResponse.class); | ||
Mockito.when(mockResponse.getBody()).thenReturn(STORE_NAME.getBytes()); | ||
Mockito.when(mockTransportclient.get(Mockito.anyString())) | ||
.thenReturn(CompletableFuture.completedFuture(mockResponse)); | ||
Mockito | ||
.when(mockMapper.readValue(Mockito.eq(STORE_NAME.getBytes()), Mockito.eq(HybridStoreQuotaStatusResponse.class))) | ||
.thenReturn(mockQuotaStatusResponse); | ||
Mockito.when(mockQuotaStatusResponse.isError()).thenReturn(false); | ||
Mockito.when(mockQuotaStatusResponse.getQuotaStatus()).thenReturn(HybridStoreQuotaStatus.QUOTA_VIOLATED); | ||
|
||
final boolean[] isReinitCalled = { false }; | ||
RouterBasedHybridStoreQuotaMonitor.TransportClientReinitProvider transportClientReinitProvider = () -> { | ||
isReinitCalled[0] = true; | ||
return mockTransportclient; | ||
}; | ||
RouterBasedHybridStoreQuotaMonitor routerBasedHybridStoreQuotaMonitor = new RouterBasedHybridStoreQuotaMonitor( | ||
mockTransportclient, | ||
STORE_NAME, | ||
Version.PushType.STREAM, | ||
TOPIC_NAME, | ||
transportClientReinitProvider); | ||
|
||
routerBasedHybridStoreQuotaMonitor.getHybridQuotaMonitorTask().setMapper(mockMapper); | ||
routerBasedHybridStoreQuotaMonitor.getHybridQuotaMonitorTask().checkStatus(); | ||
|
||
Assert.assertFalse(isReinitCalled[0]); | ||
Assert.assertEquals(routerBasedHybridStoreQuotaMonitor.getCurrentStatus(), HybridStoreQuotaStatus.QUOTA_VIOLATED); | ||
} | ||
} |