Search in sources :

Example 6 with AzureBlobConfig

use of org.apache.samza.system.azureblob.AzureBlobConfig in project samza by apache.

the class TestAzureBlobSystemProducer method setup.

@Before
public void setup() throws Exception {
    AzureBlobConfig azureBlobConfig = new AzureBlobConfig(getBasicConfigs());
    mockMetricsRegistry = mock(MetricsRegistry.class);
    mockErrorCounter = mock(Counter.class);
    when(mockMetricsRegistry.newCounter(anyString(), anyString())).thenReturn(mock(Counter.class));
    when(mockMetricsRegistry.newCounter(SOURCE, AzureBlobBasicMetrics.EVENT_PRODUCE_ERROR)).thenReturn(mockErrorCounter);
    ome = createOME(STREAM);
    mockThreadPoolExecutor = spy(new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>()));
    PowerMockito.whenNew(ThreadPoolExecutor.class).withAnyArguments().thenReturn(mockThreadPoolExecutor);
    mockAzureWriter = mock(AzureBlobWriter.class);
    doNothing().when(mockAzureWriter).close();
    systemProducer = spy(new AzureBlobSystemProducer(SYSTEM_NAME, azureBlobConfig, mockMetricsRegistry));
    // use mock writer impl
    setupWriterForProducer(systemProducer, mockAzureWriter, STREAM);
    // bypass Azure connection setup
    doNothing().when(systemProducer).setupAzureContainer();
}
Also used : MetricsRegistry(org.apache.samza.metrics.MetricsRegistry) Counter(org.apache.samza.metrics.Counter) AzureBlobConfig(org.apache.samza.system.azureblob.AzureBlobConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Before(org.junit.Before)

Example 7 with AzureBlobConfig

use of org.apache.samza.system.azureblob.AzureBlobConfig in project samza by apache.

the class TestAzureBlobSystemProducer method testSendWhenWriterCreateFails.

@Test
public void testSendWhenWriterCreateFails() throws Exception {
    AzureBlobConfig azureBlobConfig = new AzureBlobConfig(getBasicConfigs());
    AzureBlobSystemProducer systemProducer = spy(new AzureBlobSystemProducer(SYSTEM_NAME, azureBlobConfig, mockMetricsRegistry));
    PowerMockito.whenNew(AzureBlobAvroWriter.class).withAnyArguments().thenThrow(new SystemProducerException("Failed"));
    // bypass Azure connection setup
    doNothing().when(systemProducer).setupAzureContainer();
    systemProducer.register(SOURCE);
    systemProducer.start();
    try {
        systemProducer.send(SOURCE, ome);
        Assert.fail("Expected exception not thrown.");
    } catch (SystemProducerException e) {
    }
    verify(mockErrorCounter).inc();
}
Also used : AzureBlobConfig(org.apache.samza.system.azureblob.AzureBlobConfig) SystemProducerException(org.apache.samza.system.SystemProducerException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AzureBlobConfig (org.apache.samza.system.azureblob.AzureBlobConfig)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Mockito.anyString (org.mockito.Mockito.anyString)5 OutgoingMessageEnvelope (org.apache.samza.system.OutgoingMessageEnvelope)4 SystemProducerException (org.apache.samza.system.SystemProducerException)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Counter (org.apache.samza.metrics.Counter)1 MetricsRegistry (org.apache.samza.metrics.MetricsRegistry)1 Before (org.junit.Before)1