use of com.microsoft.appcenter.ingestion.OneCollectorIngestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelPauseResumeTest method pauseResumeTargetToken.
@Test
public void pauseResumeTargetToken() throws Persistence.PersistenceException {
/* Mock database and ingestion. */
Persistence persistence = mock(Persistence.class);
OneCollectorIngestion ingestion = mock(OneCollectorIngestion.class);
when(ingestion.isEnabled()).thenReturn(true);
/* Create a channel with a log group that send logs 1 by 1. */
AppCenterIngestion appCenterIngestion = mock(AppCenterIngestion.class);
when(appCenterIngestion.isEnabled()).thenReturn(true);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, appCenterIngestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, ingestion, null);
/* Reset to verify further interactions besides initial check after adding group. */
reset(persistence);
/* Pause token. */
String targetToken = "iKey-apiKey";
channel.pauseGroup(TEST_GROUP, targetToken);
/* Mock the database to return logs now. */
when(persistence.getLogs(any(String.class), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
when(persistence.countLogs(TEST_GROUP)).thenReturn(1);
/* Enqueue a log. */
Log log = mock(Log.class);
when(log.getTransmissionTargetTokens()).thenReturn(Collections.singleton(targetToken));
channel.enqueue(log, TEST_GROUP, Flags.DEFAULTS);
/* Verify persisted but not incrementing and checking logs. */
verify(persistence).putLog(log, TEST_GROUP, Flags.NORMAL);
assertEquals(0, channel.getGroupState(TEST_GROUP).mPendingLogCount);
verify(persistence, never()).countLogs(TEST_GROUP);
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Pausing a second time has no effect. */
channel.pauseGroup(TEST_GROUP, targetToken);
verify(persistence, never()).countLogs(TEST_GROUP);
/* Enqueueing a log from another transmission target works. */
Log otherLog = mock(Log.class);
when(otherLog.getTransmissionTargetTokens()).thenReturn(Collections.singleton("iKey2-apiKey2"));
channel.enqueue(otherLog, TEST_GROUP, Flags.DEFAULTS);
verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
reset(ingestion);
/* Resume token. */
channel.resumeGroup(TEST_GROUP, targetToken);
verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Sending more logs works now. */
reset(ingestion);
channel.enqueue(log, TEST_GROUP, Flags.DEFAULTS);
verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Calling resume a second time has 0 effect. */
reset(persistence);
reset(ingestion);
channel.resumeGroup(TEST_GROUP, targetToken);
verifyZeroInteractions(persistence);
verifyZeroInteractions(ingestion);
/* AppCenter ingestion never used. */
verify(appCenterIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.ingestion.OneCollectorIngestion in project mobile-center-sdk-android by Microsoft.
the class OneCollectorChannelListenerTest method setLogUrl.
@Test
public void setLogUrl() {
OneCollectorIngestion ingestion = mock(OneCollectorIngestion.class);
when(ingestion.isEnabled()).thenReturn(true);
OneCollectorChannelListener listener = new OneCollectorChannelListener(ingestion, mock(Channel.class), mock(LogSerializer.class), UUID.randomUUID());
/* Set the log url. */
String logUrl = "http://mock";
listener.setLogUrl(logUrl);
verify(ingestion).setLogUrl(logUrl);
}
use of com.microsoft.appcenter.ingestion.OneCollectorIngestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelPauseResumeTest method pauseGroupPauseTargetResumeGroupResumeTarget.
@Test
public void pauseGroupPauseTargetResumeGroupResumeTarget() throws Persistence.PersistenceException {
/* Mock database and ingestion. */
Persistence persistence = mock(Persistence.class);
OneCollectorIngestion ingestion = mock(OneCollectorIngestion.class);
when(ingestion.isEnabled()).thenReturn(true);
AppCenterIngestion appCenterIngestion = mock(AppCenterIngestion.class);
when(appCenterIngestion.isEnabled()).thenReturn(true);
/* Create a channel with a log group that send logs 1 by 1. */
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, appCenterIngestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, ingestion, null);
/* Pause group first. */
channel.pauseGroup(TEST_GROUP, null);
/* Pause token. */
String targetToken = "iKey-apiKey";
channel.pauseGroup(TEST_GROUP, targetToken);
/* Mock the database to return logs now. */
when(persistence.getLogs(any(String.class), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
when(persistence.countLogs(TEST_GROUP)).thenReturn(1);
/* Enqueue a log. */
Log log = mock(Log.class);
when(log.getTransmissionTargetTokens()).thenReturn(Collections.singleton(targetToken));
channel.enqueue(log, TEST_GROUP, Flags.DEFAULTS);
/* Verify persisted but not incrementing and checking logs. */
verify(persistence).putLog(log, TEST_GROUP, Flags.NORMAL);
assertEquals(0, channel.getGroupState(TEST_GROUP).mPendingLogCount);
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Resume group should not send the log. */
channel.resumeGroup(TEST_GROUP, null);
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Resume token, send the log now. */
channel.resumeGroup(TEST_GROUP, targetToken);
verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
Aggregations