use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method setLogUrl.
@Test
@SuppressWarnings("unchecked")
public void setLogUrl() {
Ingestion ingestion = mock(Ingestion.class);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mock(Persistence.class), ingestion, mCoreHandler);
String logUrl = "http://mockUrl";
channel.setLogUrl(logUrl);
verify(ingestion).setLogUrl(logUrl);
}
use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.
the class DefaultChannelTest method initialLogsMoreThan1Batch.
@Test
@SuppressWarnings("unchecked")
public void initialLogsMoreThan1Batch() throws IOException, InterruptedException {
AtomicReference<Runnable> runnable = catchPostRunnable();
Ingestion ingestion = mock(Ingestion.class);
doThrow(new IOException()).when(ingestion).close();
Persistence persistence = mock(Persistence.class);
when(persistence.countLogs(anyString())).thenReturn(103);
when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(50)).thenAnswer(getGetLogsAnswer(50)).thenAnswer(getGetLogsAnswer(3));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion, mCoreHandler);
channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
verify(ingestion, times(2)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
assertEquals(3, channel.getCounter(TEST_GROUP));
assertNotNull(runnable.get());
runnable.get().run();
verify(ingestion, times(3)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(mHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
verify(mHandler, never()).removeCallbacks(any(Runnable.class));
}
use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.
the class DefaultChannelTest method initialLogsThenDisable.
@Test
@SuppressWarnings("unchecked")
public void initialLogsThenDisable() throws IOException, InterruptedException {
AtomicReference<Runnable> runnable = catchPostRunnable();
Ingestion ingestion = mock(Ingestion.class);
doThrow(new IOException()).when(ingestion).close();
Persistence persistence = mock(Persistence.class);
when(persistence.countLogs(anyString())).thenReturn(3);
when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(3));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion, mCoreHandler);
channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
assertEquals(3, channel.getCounter(TEST_GROUP));
verify(mHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
channel.setEnabled(false);
verify(mHandler).removeCallbacks(any(Runnable.class));
verify(ingestion).close();
verify(persistence).deleteLogs(TEST_GROUP);
assertNotNull(runnable.get());
runnable.get().run();
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.
the class DefaultChannelTest method suspendWithoutFailureCallback.
@Test
@SuppressWarnings("unchecked")
public void suspendWithoutFailureCallback() {
Ingestion mockIngestion = mock(Ingestion.class);
Persistence mockPersistence = mock(Persistence.class);
when(mockPersistence.countLogs(anyString())).thenReturn(3);
when(mockPersistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(1));
when(mockIngestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).then(getSendAsyncAnswer(new SocketException()));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mockPersistence, mockIngestion, mCoreHandler);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
assertFalse(channel.isEnabled());
}
use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.
the class DefaultChannelTest method initialLogs.
@Test
@SuppressWarnings("unchecked")
public void initialLogs() throws IOException, InterruptedException {
AtomicReference<Runnable> runnable = catchPostRunnable();
Ingestion ingestion = mock(Ingestion.class);
doThrow(new IOException()).when(ingestion).close();
Persistence persistence = mock(Persistence.class);
when(persistence.countLogs(anyString())).thenReturn(3);
when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(3));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion, mCoreHandler);
channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
assertEquals(3, channel.getCounter(TEST_GROUP));
assertNotNull(runnable.get());
runnable.get().run();
verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(mHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
verify(mHandler, never()).removeCallbacks(any(Runnable.class));
}
Aggregations