use of com.microsoft.azure.mobile.ingestion.models.json.DefaultLogSerializer in project mobile-center-sdk-android by Microsoft.
the class DatabasePersistenceAndroidTest method getLogs.
@Test
public void getLogs() throws PersistenceException, IOException {
/* Initialize database persistence. */
DatabasePersistence persistence = new DatabasePersistence("test-persistence", "getLogs", 1);
/* Set a mock log serializer. */
LogSerializer logSerializer = new DefaultLogSerializer();
logSerializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory());
persistence.setLogSerializer(logSerializer);
try {
/* Test constants. */
int numberOfLogs = 10;
int sizeForGetLogs = 4;
/* Generate a log and persist. */
Log[] logs = new Log[numberOfLogs];
for (int i = 0; i < logs.length; i++) logs[i] = AndroidTestUtils.generateMockLog();
/* Put. */
for (Log log : logs) persistence.putLog("test", log);
/* Get. */
getAllLogs(persistence, numberOfLogs, sizeForGetLogs);
/* Clear ids, we should be able to get the logs again in the same sequence. */
persistence.clearPendingLogState();
getAllLogs(persistence, numberOfLogs, sizeForGetLogs);
/* Count. */
assertEquals(10, persistence.countLogs("test"));
/* Clear. Nothing to get after. */
persistence.mDatabaseStorage.clear();
List<Log> outputLogs = new ArrayList<>();
assertNull(persistence.getLogs("test", sizeForGetLogs, outputLogs));
assertTrue(outputLogs.isEmpty());
assertEquals(0, persistence.countLogs("test"));
} finally {
/* Close. */
//noinspection ThrowFromFinallyBlock
persistence.close();
}
}
Aggregations