use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method trackExceptionForWrapperSdk.
@Test
public void trackExceptionForWrapperSdk() {
StackFrame frame = new StackFrame();
frame.setClassName("1");
frame.setFileName("2");
frame.setLineNumber(3);
frame.setMethodName("4");
final com.microsoft.azure.mobile.crashes.ingestion.models.Exception exception = new com.microsoft.azure.mobile.crashes.ingestion.models.Exception();
exception.setType("5");
exception.setMessage("6");
exception.setFrames(singletonList(frame));
Crashes crashes = Crashes.getInstance();
Channel mockChannel = mock(Channel.class);
Crashes.getInstance().trackException(exception);
verify(mockChannel, never()).enqueue(any(Log.class), eq(crashes.getGroupName()));
crashes.onStarted(mock(Context.class), "", mockChannel);
Crashes.getInstance().trackException(exception);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof ManagedErrorLog && exception.equals(((ManagedErrorLog) item).getException());
}
}), eq(crashes.getGroupName()));
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method shutdownInterrupted.
@Test
public void shutdownInterrupted() throws Exception {
Persistence mockPersistence = mock(Persistence.class);
IngestionHttp mockIngestion = mock(IngestionHttp.class);
Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
DatabasePersistenceAsync mockPersistenceAsync = spy(new DatabasePersistenceAsync(mockPersistence));
whenNew(DatabasePersistenceAsync.class).withArguments(mockPersistence).thenReturn(mockPersistenceAsync);
when(mockPersistence.getLogs(any(String.class), anyInt(), Matchers.<List<Log>>any())).then(getGetLogsAnswer(1));
doThrow(new InterruptedException()).when(mockPersistenceAsync).waitForCurrentTasksToComplete(anyLong());
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 1 event. */
channel.enqueue(mock(Log.class), TEST_GROUP);
verify(mockListener).onBeforeSending(notNull(Log.class));
channel.shutdown();
verify(mockListener, never()).onFailure(any(Log.class), any(Exception.class));
verify(mockPersistence).clearPendingLogState();
verify(mockPersistenceAsync).waitForCurrentTasksToComplete(DefaultChannel.SHUTDOWN_TIMEOUT);
verifyStatic();
MobileCenterLog.warn(eq(MobileCenterLog.LOG_TAG), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof InterruptedException;
}
}));
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method invokeCallbacksAfterSuspendRecoverable.
@Test
@SuppressWarnings("unchecked")
public void invokeCallbacksAfterSuspendRecoverable() throws Exception {
Persistence mockPersistence = mock(Persistence.class);
IngestionHttp mockIngestion = mock(IngestionHttp.class);
Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
DatabasePersistenceAsync mockPersistenceAsync = spy(new DatabasePersistenceAsync(mockPersistence));
whenNew(DatabasePersistenceAsync.class).withArguments(mockPersistence).thenReturn(mockPersistenceAsync);
when(mockPersistence.getLogs(eq(TEST_GROUP), anyInt(), any(ArrayList.class))).then(getGetLogsAnswer(1));
when(mockIngestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).then(getSendAsyncAnswer(new HttpException(503)));
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mockPersistence, mockIngestion);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, mockListener);
channel.addGroup(TEST_GROUP + "2", 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
/* Enqueuing 1 event. */
channel.enqueue(mock(Log.class), TEST_GROUP);
/* Verify callbacks invoked only for the first log. */
verify(mockListener).onBeforeSending(any(Log.class));
/* Verify no failure forwarded. */
verify(mockListener, never()).onFailure(any(Log.class), any(Exception.class));
/* Verify no log was deleted. */
verify(mockPersistence, never()).deleteLogs(TEST_GROUP);
/* But that we cleared batch state. */
verify(mockPersistence).clearPendingLogState();
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method invalidGroup.
@Test
public void invalidGroup() throws Persistence.PersistenceException {
Persistence persistence = mock(Persistence.class);
Channel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, mock(Ingestion.class));
/* Enqueue a log before group is registered = failure. */
Log log = mock(Log.class);
channel.enqueue(log, TEST_GROUP);
verify(log, never()).setDevice(any(Device.class));
verify(log, never()).setToffset(anyLong());
verify(persistence, never()).putLog(TEST_GROUP, log);
/* Trying remove group that not registered. */
channel.removeGroup(TEST_GROUP);
verify(mHandler, never()).removeCallbacks(any(Runnable.class));
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class DatabasePersistenceTest method clearPendingLogState.
@Test
public void clearPendingLogState() throws JSONException {
/* groupCount should be <= 9. */
final int groupCount = 4;
final int logCount = 10;
/* Mock logs. */
List<List<ContentValues>> list = new ArrayList<>();
for (int i = 0; i < groupCount; i++) {
List<ContentValues> iterator = new ArrayList<>();
for (long l = 1; l <= logCount; l++) {
ContentValues values = mock(ContentValues.class);
when(values.getAsLong(DatabaseManager.PRIMARY_KEY)).thenReturn(l + i * logCount);
when(values.getAsString(DatabasePersistence.COLUMN_LOG)).thenReturn("{}");
iterator.add(values);
}
list.add(iterator);
}
/* Mock instances. */
mockStatic(StorageHelper.DatabaseStorage.class);
StorageHelper.DatabaseStorage mockDatabaseStorage = mock(StorageHelper.DatabaseStorage.class);
when(StorageHelper.DatabaseStorage.getDatabaseStorage(anyString(), anyString(), anyInt(), any(ContentValues.class), anyInt(), any(StorageHelper.DatabaseStorage.DatabaseErrorListener.class))).thenReturn(mockDatabaseStorage);
for (int i = 0; i < groupCount; i++) {
StorageHelper.DatabaseStorage.DatabaseScanner mockDatabaseScanner = mock(StorageHelper.DatabaseStorage.DatabaseScanner.class);
when(mockDatabaseScanner.iterator()).thenReturn(list.get(i).iterator());
when(mockDatabaseStorage.getScanner(COLUMN_GROUP, String.valueOf(i))).thenReturn(mockDatabaseScanner);
}
LogSerializer mockLogSerializer = mock(LogSerializer.class);
when(mockLogSerializer.deserializeLog(anyString())).thenReturn(mock(Log.class));
/* Instantiate Database Persistence. */
DatabasePersistence persistence = new DatabasePersistence();
persistence.setLogSerializer(mockLogSerializer);
/* Get logs. */
for (int i = 0; i < groupCount; i++) {
persistence.getLogs(String.valueOf(i), logCount, new ArrayList<Log>());
}
/* Verify there are 4 pending groups. */
assertEquals(groupCount, persistence.mPendingDbIdentifiersGroups.size());
assertEquals(groupCount * logCount, persistence.mPendingDbIdentifiers.size());
/* Clear all pending groups and verify. */
persistence.clearPendingLogState();
assertEquals(0, persistence.mPendingDbIdentifiersGroups.size());
assertEquals(0, persistence.mPendingDbIdentifiers.size());
}
Aggregations