use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method initialLogs.
@Test
public void initialLogs() 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));
/* Create channel. */
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(3, channel.getGroupState(TEST_GROUP).mPendingLogCount);
delayedRunnable.getValue().run();
verify(ingestion).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));
}
use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method setEnabled.
@Test
public void setEnabled() throws IOException {
/* Send a log. */
Ingestion ingestion = mock(Ingestion.class);
when(ingestion.isEnabled()).thenReturn(true);
doThrow(new IOException()).when(ingestion).close();
Persistence persistence = mock(Persistence.class);
when(persistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).thenAnswer(getGetLogsAnswer(1));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, ingestion, mAppCenterHandler);
Channel.Listener listener = spy(new AbstractChannelListener());
channel.addListener(listener);
channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
channel.enqueue(mock(Log.class), TEST_GROUP, Flags.DEFAULTS);
verify(mAppCenterHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
/* Disable before timer is triggered. */
channel.setEnabled(false);
verify(mAppCenterHandler).removeCallbacks(any(Runnable.class));
verify(ingestion).close();
verify(persistence).deleteLogs(TEST_GROUP);
verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(listener).onGloballyEnabled(false);
/* Enable and send a new log. */
ArgumentCaptor<Runnable> delayedRunnable = ArgumentCaptor.forClass(Runnable.class);
when(mAppCenterHandler.postDelayed(delayedRunnable.capture(), anyLong())).thenReturn(true);
channel.setEnabled(true);
channel.enqueue(mock(Log.class), TEST_GROUP, Flags.DEFAULTS);
delayedRunnable.getValue().run();
verify(ingestion).reopen();
verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(listener).onGloballyEnabled(true);
}
use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelAlternateIngestionTest method startWithoutAppSecret.
@Test
public void startWithoutAppSecret() throws Persistence.PersistenceException {
/* Set up channel without app secret. */
String appCenterGroup = "test_group1";
String oneCollectorGroup = "test_group2";
Persistence mockPersistence = mock(Persistence.class);
Ingestion defaultIngestion = mock(Ingestion.class);
when(defaultIngestion.isEnabled()).thenReturn(true);
Ingestion alternateIngestion = mock(Ingestion.class);
when(alternateIngestion.isEnabled()).thenReturn(true);
/* Simulate we have 1 pending log in storage. */
when(mockPersistence.countLogs(anyString())).thenReturn(1);
when(mockPersistence.getLogs(any(String.class), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
/* Create channel and groups. */
DefaultChannel channel = new DefaultChannel(mock(Context.class), null, mockPersistence, defaultIngestion, mAppCenterHandler);
channel.addGroup(appCenterGroup, 2, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
channel.addGroup(oneCollectorGroup, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, alternateIngestion, null);
/* App center previous log not sent yet. */
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* One collector previous log sent. */
verify(alternateIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Enqueuing 1 new event for app center. */
channel.enqueue(mock(Log.class), appCenterGroup, Flags.DEFAULTS);
/* Not sent. */
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Verify we didn't persist the log since AppCenter not started with app secret. */
verify(mockPersistence, never()).putLog(any(Log.class), eq(appCenterGroup), eq(Flags.NORMAL));
/* Enqueuing 1 event from one collector group. */
channel.enqueue(mock(Log.class), oneCollectorGroup, Flags.DEFAULTS);
/* Verify that we have called sendAsync on the alternate ingestion a second time. */
verify(alternateIngestion, times(2)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Verify that we can now send logs to app center after we have set app secret. */
channel.setAppSecret("testAppSecret");
channel.enqueue(mock(Log.class), appCenterGroup, Flags.DEFAULTS);
verify(defaultIngestion).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 DefaultChannelAlternateIngestionTest method pendingLogsDisableSetAppSecretThenEnable.
@Test
public void pendingLogsDisableSetAppSecretThenEnable() {
/* Set up channel without app secret. */
String appCenterGroup = "test_group1";
String oneCollectorGroup = "test_group2";
Persistence mockPersistence = mock(Persistence.class);
Ingestion defaultIngestion = mock(Ingestion.class);
when(defaultIngestion.isEnabled()).thenReturn(true);
Ingestion alternateIngestion = mock(Ingestion.class);
when(alternateIngestion.isEnabled()).thenReturn(true);
when(mockPersistence.getLogs(any(String.class), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
/* Simulate we have 1 pending log in storage for App Center. */
when(mockPersistence.countLogs(appCenterGroup)).thenReturn(1);
/* Create channel with the two groups. */
DefaultChannel channel = new DefaultChannel(mock(Context.class), null, mockPersistence, defaultIngestion, mAppCenterHandler);
channel.addGroup(appCenterGroup, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
channel.addGroup(oneCollectorGroup, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, alternateIngestion, null);
/* Disable channel. */
channel.setEnabled(false);
/* Verify that no log is sent even if we set app secret while channel is disabled. */
channel.setAppSecret("testAppSecret");
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(alternateIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Enable channel. */
channel.setEnabled(true);
/* Verify that now logs are sent when channel is enabled. */
verify(defaultIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(alternateIngestion, 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 DefaultChannelOtherOperationsTest method setLogUrl.
@Test
public void setLogUrl() {
Ingestion ingestion = mock(Ingestion.class);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mock(Persistence.class), ingestion, mAppCenterHandler);
String logUrl = "http://mockUrl";
channel.setLogUrl(logUrl);
verify(ingestion).setLogUrl(logUrl);
}
Aggregations