use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-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 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, mCoreHandler);
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.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method suspendWithFailureCallback.
@Test
public void suspendWithFailureCallback() {
Ingestion mockIngestion = mock(Ingestion.class);
Persistence mockPersistence = mock(Persistence.class);
Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
when(mockPersistence.countLogs(anyString())).thenReturn(30);
when(mockPersistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).thenAnswer(getGetLogsAnswer(10));
when(mockIngestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
return null;
}
}).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
return null;
}
}).then(getSendAsyncAnswer(new HttpException(new HttpResponse(404))));
when(mockIngestion.isEnabled()).thenReturn(true);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mockPersistence, mockIngestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, mockListener);
/* 30 from countLogs and 10 new logs from getLogs. */
verify(mockListener, times(40)).onBeforeSending(any(Log.class));
verify(mockListener, times(40)).onFailure(any(Log.class), any(SocketException.class));
assertFalse(channel.isEnabled());
}
use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method initialLogsThenDisable.
@Test
public void initialLogsThenDisable() throws IOException {
ArgumentCaptor<Runnable> delayedRunnable = ArgumentCaptor.forClass(Runnable.class);
when(mAppCenterHandler.postDelayed(delayedRunnable.capture(), anyLong())).thenReturn(true);
Ingestion ingestion = mock(Ingestion.class);
when(ingestion.isEnabled()).thenReturn(true);
doThrow(new IOException()).when(ingestion).close();
Persistence persistence = mock(Persistence.class);
when(persistence.countLogs(anyString())).thenReturn(3);
when(persistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).thenAnswer(getGetLogsAnswer(3));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, ingestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
assertEquals(3, channel.getGroupState(TEST_GROUP).mPendingLogCount);
verify(mAppCenterHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
channel.setEnabled(false);
verify(mAppCenterHandler).removeCallbacks(any(Runnable.class));
verify(ingestion).close();
verify(persistence).deleteLogs(TEST_GROUP);
delayedRunnable.getValue().run();
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method somehowDatabaseEmptiedAfterTimer.
@Test
public void somehowDatabaseEmptiedAfterTimer() throws IOException {
/* Cover the if (batchId != null) test though it could happen only if the database content disappear after the timer... */
ArgumentCaptor<Runnable> delayedRunnable = ArgumentCaptor.forClass(Runnable.class);
when(mAppCenterHandler.postDelayed(delayedRunnable.capture(), anyLong())).thenReturn(true);
Ingestion ingestion = mock(Ingestion.class);
when(ingestion.isEnabled()).thenReturn(true);
doThrow(new IOException()).when(ingestion).close();
Persistence persistence = mock(Persistence.class);
when(persistence.countLogs(anyString())).thenReturn(2);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, ingestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
assertEquals(2, channel.getGroupState(TEST_GROUP).mPendingLogCount);
delayedRunnable.getValue().run();
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(mAppCenterHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
verify(mAppCenterHandler, never()).removeCallbacks(any(Runnable.class));
}
Aggregations