use of com.microsoft.azure.mobile.ingestion.Ingestion in project mobile-center-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);
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.azure.mobile.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method errorLogSuccess.
@Test
@SuppressWarnings("unchecked")
public void errorLogSuccess() throws Persistence.PersistenceException {
Persistence mockPersistence = mock(Persistence.class);
Ingestion mockIngestion = mock(Ingestion.class);
Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
when(mockPersistence.getLogs(any(String.class), anyInt(), any(ArrayList.class))).then(getGetLogsAnswer());
when(mockIngestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).then(getSendAsyncAnswer());
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mockPersistence, mockIngestion);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, mockListener);
/* Enqueuing 2 error logs. */
channel.enqueue(mock(Log.class), TEST_GROUP);
channel.enqueue(mock(Log.class), TEST_GROUP);
/* Verify that 2 items have been persisted. */
verify(mockPersistence, times(2)).putLog(eq(TEST_GROUP), any(Log.class));
/* Verify that we have called sendAsync on the ingestion twice as batch size is 1. */
verify(mockIngestion, times(2)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Verify that we have called deleteLogs on the Persistence. */
verify(mockPersistence, times(2)).deleteLogs(any(String.class), any(String.class));
/* Verify that we have called onBeforeSending in the listener. */
verify(mockListener, times(2)).onBeforeSending(any(Log.class));
/* Verify that we have called onSuccess in the listener. */
verify(mockListener, times(2)).onSuccess(any(Log.class));
/* The counter should be 0 now as we sent data. */
assertEquals(0, channel.getCounter(TEST_GROUP));
/* Verify timer. */
verify(mHandler, never()).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
verify(mHandler, never()).removeCallbacks(any(Runnable.class));
}
use of com.microsoft.azure.mobile.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method disableBeforeCheckingPendingLogs.
@Test
@SuppressWarnings("unchecked")
public void disableBeforeCheckingPendingLogs() throws IOException {
Ingestion ingestion = mock(Ingestion.class);
Persistence persistence = mock(Persistence.class);
final DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion);
when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(1));
when(ingestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).thenAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
/* Simulate a service disabled in the middle of network transaction. */
ServiceCallback callback = (ServiceCallback) invocation.getArguments()[3];
channel.removeGroup(TEST_GROUP);
callback.onCallSucceeded("");
return null;
}
});
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
channel.enqueue(mock(Log.class), TEST_GROUP);
verify(mHandler, never()).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
/* checkPendingLogs is getting called twice from triggerIngestion and a callback for ingestion.
It can be failed because of timing issue so checking at least once instead. */
verifyStatic(atLeastOnce());
MobileCenterLog.info(eq(MobileCenter.LOG_TAG), anyString());
}
use of com.microsoft.azure.mobile.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method somehowDatabaseEmptiedAfterTimer.
@Test
@SuppressWarnings("unchecked")
public void somehowDatabaseEmptiedAfterTimer() throws IOException, InterruptedException {
/* Cover the if (batchId != null) test though it could happen only if the database content disappear after the timer... */
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(2);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion);
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(2, channel.getCounter(TEST_GROUP));
assertNotNull(runnable.get());
runnable.get().run();
verify(ingestion, never()).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.azure.mobile.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);
String logUrl = "http://mockUrl";
channel.setLogUrl(logUrl);
verify(ingestion).setLogUrl(logUrl);
}
Aggregations