Search in sources :

Example 1 with Data

use of com.microsoft.appcenter.ingestion.models.one.Data in project mobile-center-sdk-android by Microsoft.

the class DatabasePersistenceAndroidTest method putLargeLogNotSupportedOnCommonSchema.

@Test
public void putLargeLogNotSupportedOnCommonSchema() throws JSONException {
    /* Initialize database persistence. */
    DatabasePersistence persistence = new DatabasePersistence(sContext);
    /* Set a mock log serializer. */
    LogSerializer logSerializer = new DefaultLogSerializer();
    logSerializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory());
    persistence.setLogSerializer(logSerializer);
    try {
        /* Initial count is 0. */
        assertEquals(0, persistence.countLogs("test-p1"));
        /* Generate a large log. */
        CommonSchemaLog log = new MockCommonSchemaLog();
        int size = 2 * 1024 * 1024;
        StringBuilder largeValue = new StringBuilder(size);
        for (int i = 0; i < size; i++) {
            largeValue.append("x");
        }
        log.setVer("3.0");
        log.setName("test");
        log.setTimestamp(new Date());
        log.addTransmissionTarget("token");
        Data data = new Data();
        log.setData(data);
        data.getProperties().put("key", largeValue.toString());
        /* Persisting that log should fail. */
        try {
            persistence.putLog(log, "test-p1", NORMAL);
            fail("Inserting large common schema log is not supposed to work");
        } catch (PersistenceException e) {
            /* Count logs is still 0 */
            e.printStackTrace();
            assertEquals(0, persistence.countLogs("test-p1"));
        }
    } finally {
        persistence.close();
    }
}
Also used : MockLogFactory(com.microsoft.appcenter.ingestion.models.json.MockLogFactory) MockCommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.MockCommonSchemaLog) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) MockCommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.MockCommonSchemaLog) PersistenceException(com.microsoft.appcenter.persistence.Persistence.PersistenceException) Data(com.microsoft.appcenter.ingestion.models.one.Data) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) SuppressLint(android.annotation.SuppressLint) Date(java.util.Date) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 MediumTest (androidx.test.filters.MediumTest)1 DefaultLogSerializer (com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer)1 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)1 MockLogFactory (com.microsoft.appcenter.ingestion.models.json.MockLogFactory)1 CommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog)1 Data (com.microsoft.appcenter.ingestion.models.one.Data)1 MockCommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.MockCommonSchemaLog)1 PersistenceException (com.microsoft.appcenter.persistence.Persistence.PersistenceException)1 Date (java.util.Date)1 Test (org.junit.Test)1