use of com.microsoft.appcenter.persistence.Persistence in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method suspendWithoutFailureCallback.
@Test
public void suspendWithoutFailureCallback() {
Ingestion mockIngestion = mock(Ingestion.class);
Persistence mockPersistence = mock(Persistence.class);
when(mockPersistence.countLogs(anyString())).thenReturn(3);
when(mockPersistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).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) {
return null;
}
}).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
return null;
}
}).then(getSendAsyncAnswer(new SocketException()));
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, null);
assertFalse(channel.isEnabled());
}
use of com.microsoft.appcenter.persistence.Persistence in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method checkPendingLogsStoresStartTime.
@Test
public void checkPendingLogsStoresStartTime() {
/* Mock current time. */
long now = 1;
when(System.currentTimeMillis()).thenReturn(now);
/* Create channel and group. */
Persistence mockPersistence = mock(Persistence.class);
when(mockPersistence.countLogs(TEST_GROUP)).thenReturn(5);
AppCenterIngestion mockIngestion = mock(AppCenterIngestion.class);
when(mockIngestion.isEnabled()).thenReturn(true);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mockPersistence, mockIngestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 10, CUSTOM_INTERVAL, MAX_PARALLEL_BATCHES, mockIngestion, mock(Channel.GroupListener.class));
/* Verify that timer starts and current time is saved into preferences. */
verifyStatic();
SharedPreferencesManager.putLong(eq(START_TIMER_PREFIX + TEST_GROUP), eq(now));
verify(mAppCenterHandler).postDelayed(any(Runnable.class), eq(CUSTOM_INTERVAL));
}
use of com.microsoft.appcenter.persistence.Persistence in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method checkPendingLogsDoesNotStartTimerWithoutLogs.
@Test
public void checkPendingLogsDoesNotStartTimerWithoutLogs() {
/* Mock current time. */
long now = 1;
when(System.currentTimeMillis()).thenReturn(now);
/* Create channel and group. */
Persistence mockPersistence = mock(Persistence.class);
when(mockPersistence.countLogs(TEST_GROUP)).thenReturn(0);
AppCenterIngestion mockIngestion = mock(AppCenterIngestion.class);
when(mockIngestion.isEnabled()).thenReturn(true);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mockPersistence, mockIngestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 10, CUSTOM_INTERVAL, MAX_PARALLEL_BATCHES, mockIngestion, mock(Channel.GroupListener.class));
/* Verify that timer isn't started. */
verifyStatic(never());
SharedPreferencesManager.putLong(eq(START_TIMER_PREFIX + TEST_GROUP), eq(now));
verify(mAppCenterHandler, never()).postDelayed(any(Runnable.class), eq(CUSTOM_INTERVAL));
}
use of com.microsoft.appcenter.persistence.Persistence in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method setNetworkRequest.
@Test
public void setNetworkRequest() {
/* Mock current time - before end of interval. */
long now = 1;
when(System.currentTimeMillis()).thenReturn(now);
/* Create channel and group. */
Persistence mockPersistence = mock(Persistence.class);
when(mockPersistence.countLogs(TEST_GROUP)).thenReturn(5);
when(mockPersistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
AppCenterIngestion mockIngestion = mock(AppCenterIngestion.class);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mockPersistence, mockIngestion, mAppCenterHandler);
/* Disallow network requests. */
when(mockIngestion.isEnabled()).thenReturn(false);
channel.setNetworkRequests(false);
channel.addGroup(TEST_GROUP, 3, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, mockIngestion, mock(Channel.GroupListener.class));
/* Verify that sending logs wasn't called. */
verify(mockIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Enable network requests and verify that sending logs was called. */
when(mockIngestion.isEnabled()).thenReturn(true);
channel.setNetworkRequests(true);
verify(mockIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Disallow network requests and verify that sending logs wasn't called. */
when(mockIngestion.isEnabled()).thenReturn(false);
channel.setNetworkRequests(false);
channel.addGroup(TEST_GROUP, 3, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, mockIngestion, mock(Channel.GroupListener.class));
verify(mockIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Allow network requests and verify that sending logs was called again. */
when(mockIngestion.isEnabled()).thenReturn(true);
channel.setNetworkRequests(true);
verify(mockIngestion, times(2)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.persistence.Persistence in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method enqueueWithFlags.
@Test
public void enqueueWithFlags() throws Persistence.PersistenceException {
/* Other tests use default flags, test explicit flags here. */
/* Setup persistence, channel and a listener. */
Persistence persistence = mock(Persistence.class);
Channel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, mock(AppCenterIngestion.class), mAppCenterHandler);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, mock(Channel.GroupListener.class));
Channel.Listener listener = mock(Channel.Listener.class);
channel.addListener(listener);
/* Enqueuing 1 event with normal persistence. */
Log normalLog = mock(Log.class);
channel.enqueue(normalLog, TEST_GROUP, Flags.NORMAL);
/* Verify listener and database get the same flags. */
verify(listener).onPreparedLog(normalLog, TEST_GROUP, Flags.NORMAL);
verify(persistence).putLog(normalLog, TEST_GROUP, Flags.NORMAL);
/* Enqueuing 1 event with critical persistence. */
Log criticalLog = mock(Log.class);
channel.enqueue(criticalLog, TEST_GROUP, Flags.CRITICAL);
/* Verify listener and database get the same flags. */
verify(listener).onPreparedLog(criticalLog, TEST_GROUP, Flags.CRITICAL);
verify(persistence).putLog(criticalLog, TEST_GROUP, Flags.CRITICAL);
}
Aggregations