Search in sources :

Example 1 with Ingestion

use of com.microsoft.appcenter.ingestion.Ingestion in project mobile-center-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);
}
Also used : Context(android.content.Context) Persistence(com.microsoft.appcenter.persistence.Persistence) Matchers.anyString(org.mockito.Matchers.anyString) Ingestion(com.microsoft.appcenter.ingestion.Ingestion) Test(org.junit.Test)

Example 2 with Ingestion

use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.

the class DefaultChannelTest method initialLogsMoreThan1Batch.

@Test
@SuppressWarnings("unchecked")
public void initialLogsMoreThan1Batch() throws IOException, InterruptedException {
    AtomicReference<Runnable> runnable = catchPostRunnable();
    Ingestion ingestion = mock(Ingestion.class);
    doThrow(new IOException()).when(ingestion).close();
    Persistence persistence = mock(Persistence.class);
    when(persistence.countLogs(anyString())).thenReturn(103);
    when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(50)).thenAnswer(getGetLogsAnswer(50)).thenAnswer(getGetLogsAnswer(3));
    DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion, mCoreHandler);
    channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
    verify(ingestion, times(2)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
    assertEquals(3, channel.getCounter(TEST_GROUP));
    assertNotNull(runnable.get());
    runnable.get().run();
    verify(ingestion, times(3)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
    verify(mHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
    verify(mHandler, never()).removeCallbacks(any(Runnable.class));
}
Also used : Persistence(com.microsoft.appcenter.persistence.Persistence) Context(android.content.Context) ServiceCallback(com.microsoft.appcenter.http.ServiceCallback) IOException(java.io.IOException) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) UUID(java.util.UUID) Ingestion(com.microsoft.appcenter.ingestion.Ingestion) Test(org.junit.Test)

Example 3 with Ingestion

use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.

the class DefaultChannelTest method initialLogsThenDisable.

@Test
@SuppressWarnings("unchecked")
public void initialLogsThenDisable() throws IOException, InterruptedException {
    AtomicReference<Runnable> runnable = catchPostRunnable();
    Ingestion ingestion = mock(Ingestion.class);
    doThrow(new IOException()).when(ingestion).close();
    Persistence persistence = mock(Persistence.class);
    when(persistence.countLogs(anyString())).thenReturn(3);
    when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(3));
    DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion, mCoreHandler);
    channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
    assertEquals(3, channel.getCounter(TEST_GROUP));
    verify(mHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
    channel.setEnabled(false);
    verify(mHandler).removeCallbacks(any(Runnable.class));
    verify(ingestion).close();
    verify(persistence).deleteLogs(TEST_GROUP);
    assertNotNull(runnable.get());
    runnable.get().run();
    verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
Also used : Persistence(com.microsoft.appcenter.persistence.Persistence) Context(android.content.Context) ServiceCallback(com.microsoft.appcenter.http.ServiceCallback) IOException(java.io.IOException) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) UUID(java.util.UUID) Ingestion(com.microsoft.appcenter.ingestion.Ingestion) Test(org.junit.Test)

Example 4 with Ingestion

use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.

the class DefaultChannelTest method suspendWithoutFailureCallback.

@Test
@SuppressWarnings("unchecked")
public void suspendWithoutFailureCallback() {
    Ingestion mockIngestion = mock(Ingestion.class);
    Persistence mockPersistence = mock(Persistence.class);
    when(mockPersistence.countLogs(anyString())).thenReturn(3);
    when(mockPersistence.getLogs(anyString(), anyInt(), anyList())).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) throws Throwable {
            return null;
        }
    }).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return null;
        }
    }).then(getSendAsyncAnswer(new SocketException()));
    DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mockPersistence, mockIngestion, mCoreHandler);
    channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
    assertFalse(channel.isEnabled());
}
Also used : Context(android.content.Context) SocketException(java.net.SocketException) Ingestion(com.microsoft.appcenter.ingestion.Ingestion) Persistence(com.microsoft.appcenter.persistence.Persistence) Answer(org.mockito.stubbing.Answer) ServiceCallback(com.microsoft.appcenter.http.ServiceCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with Ingestion

use of com.microsoft.appcenter.ingestion.Ingestion in project AppCenter-SDK-Android by Microsoft.

the class DefaultChannelTest method initialLogs.

@Test
@SuppressWarnings("unchecked")
public void initialLogs() throws IOException, InterruptedException {
    AtomicReference<Runnable> runnable = catchPostRunnable();
    Ingestion ingestion = mock(Ingestion.class);
    doThrow(new IOException()).when(ingestion).close();
    Persistence persistence = mock(Persistence.class);
    when(persistence.countLogs(anyString())).thenReturn(3);
    when(persistence.getLogs(anyString(), anyInt(), anyList())).thenAnswer(getGetLogsAnswer(3));
    DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), persistence, ingestion, mCoreHandler);
    channel.addGroup(TEST_GROUP, 50, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null);
    verify(ingestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
    assertEquals(3, channel.getCounter(TEST_GROUP));
    assertNotNull(runnable.get());
    runnable.get().run();
    verify(ingestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
    verify(mHandler).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
    verify(mHandler, never()).removeCallbacks(any(Runnable.class));
}
Also used : Persistence(com.microsoft.appcenter.persistence.Persistence) Context(android.content.Context) ServiceCallback(com.microsoft.appcenter.http.ServiceCallback) IOException(java.io.IOException) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) UUID(java.util.UUID) Ingestion(com.microsoft.appcenter.ingestion.Ingestion) Test(org.junit.Test)

Aggregations

Ingestion (com.microsoft.appcenter.ingestion.Ingestion)31 Context (android.content.Context)29 Persistence (com.microsoft.appcenter.persistence.Persistence)29 Test (org.junit.Test)29 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)24 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)24 UUID (java.util.UUID)24 Log (com.microsoft.appcenter.ingestion.models.Log)20 Matchers.anyString (org.mockito.Matchers.anyString)19 AppCenterIngestion (com.microsoft.appcenter.ingestion.AppCenterIngestion)14 IOException (java.io.IOException)13 SocketException (java.net.SocketException)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 HttpException (com.microsoft.appcenter.http.HttpException)4 Answer (org.mockito.stubbing.Answer)4 CancellationException (com.microsoft.appcenter.CancellationException)3 ArrayList (java.util.ArrayList)3 HttpResponse (com.microsoft.appcenter.http.HttpResponse)2 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)1 HashMap (java.util.HashMap)1