use of com.microsoft.appcenter.ingestion.models.LogWithProperties in project AppCenter-SDK-Android by Microsoft.
the class SasquatchAnalyticsListener method onSendingSucceeded.
@Override
public void onSendingSucceeded(com.microsoft.appcenter.ingestion.models.Log log) {
String message = null;
if (log instanceof EventLog) {
message = String.format("%s\nName: %s", mContext.getString(R.string.event_sent_succeeded), ((EventLog) log).getName());
} else if (log instanceof PageLog) {
message = String.format("%s\nName: %s", mContext.getString(R.string.page_sent_succeeded), ((PageLog) log).getName());
}
if (message != null) {
if (((LogWithProperties) log).getProperties() != null) {
message += String.format("\nProperties: %s", new JSONObject(((LogWithProperties) log).getProperties()).toString());
}
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
}
analyticsIdlingResource.decrement();
}
use of com.microsoft.appcenter.ingestion.models.LogWithProperties in project AppCenter-SDK-Android by Microsoft.
the class DatabasePersistenceAndroidTest method putLargeLogAndDeleteAll.
@Test
public void putLargeLogAndDeleteAll() throws PersistenceException, IOException {
/* Initialize database persistence. */
DatabasePersistence persistence = new DatabasePersistence("test-persistence", "putLargeLog", 1);
/* 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 and persist. */
LogWithProperties log = AndroidTestUtils.generateMockLog();
int size = 2 * 1024 * 1024;
StringBuilder largeValue = new StringBuilder(size);
for (int i = 0; i < size; i++) {
largeValue.append("x");
}
Map<String, String> properties = new HashMap<>();
properties.put("key", largeValue.toString());
log.setProperties(properties);
long id = persistence.putLog("test-p1", log);
/* Count logs. */
assertEquals(1, persistence.countLogs("test-p1"));
/* Get a log from persistence. */
List<Log> outputLogs = new ArrayList<>();
persistence.getLogs("test-p1", 1, outputLogs);
assertEquals(1, outputLogs.size());
assertEquals(log, outputLogs.get(0));
assertEquals(1, persistence.countLogs("test-p1"));
/* Verify large file. */
File file = persistence.getLargePayloadFile(persistence.getLargePayloadGroupDirectory("test-p1"), id);
assertNotNull(file);
String fileLog = StorageHelper.InternalStorage.read(file);
assertNotNull(fileLog);
assertTrue(fileLog.length() >= size);
/* Delete entire group. */
persistence.deleteLogs("test-p1");
assertEquals(0, persistence.countLogs("test-p1"));
/* Verify file delete and also parent directory since we used group deletion. */
assertFalse(file.exists());
assertFalse(file.getParentFile().exists());
} finally {
/* Close. */
// noinspection ThrowFromFinallyBlock
persistence.close();
}
}
use of com.microsoft.appcenter.ingestion.models.LogWithProperties in project AppCenter-SDK-Android by Microsoft.
the class DatabasePersistenceAndroidTest method putLargeLogFails.
@Test
public void putLargeLogFails() throws PersistenceException, IOException {
/* Initialize database persistence. */
String path = Constants.FILES_PATH;
Constants.FILES_PATH = null;
DatabasePersistence persistence = new DatabasePersistence("test-persistence", "putLargeLogException", 1);
/* 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 and persist. */
LogWithProperties log = AndroidTestUtils.generateMockLog();
int size = 2 * 1024 * 1024;
StringBuilder largeValue = new StringBuilder(size);
for (int i = 0; i < size; i++) {
largeValue.append("x");
}
Map<String, String> properties = new HashMap<>();
properties.put("key", largeValue.toString());
log.setProperties(properties);
persistence.putLog("test-p1", log);
fail("putLog was expected to fail");
} catch (Persistence.PersistenceException e) {
assertTrue(e.getCause() instanceof IOException);
/* Make sure database entry has been removed. */
assertEquals(0, persistence.countLogs("test-p1"));
} finally {
/* Close. */
// noinspection ThrowFromFinallyBlock
persistence.close();
/* Restore path. */
Constants.FILES_PATH = path;
}
}
use of com.microsoft.appcenter.ingestion.models.LogWithProperties in project AppCenter-SDK-Android by Microsoft.
the class DatabasePersistenceAndroidTest method putLargeLogFailsToRead.
@Test
public void putLargeLogFailsToRead() throws PersistenceException, IOException {
/* Initialize database persistence. */
DatabasePersistence persistence = new DatabasePersistence("test-persistence", "putLargeLogException", 1);
/* 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 and persist. */
LogWithProperties log = AndroidTestUtils.generateMockLog();
int size = 2 * 1024 * 1024;
StringBuilder largeValue = new StringBuilder(size);
for (int i = 0; i < size; i++) {
largeValue.append("x");
}
Map<String, String> properties = new HashMap<>();
properties.put("key", largeValue.toString());
log.setProperties(properties);
long id = persistence.putLog("test-p1", log);
assertEquals(1, persistence.countLogs("test-p1"));
/* Verify large file. */
File file = persistence.getLargePayloadFile(persistence.getLargePayloadGroupDirectory("test-p1"), id);
assertNotNull(file);
String fileLog = StorageHelper.InternalStorage.read(file);
assertNotNull(fileLog);
assertTrue(fileLog.length() >= size);
/* Delete the file. */
assertTrue(file.delete());
/* We won't be able to read the log now but persistence should delete the SQLite log on error. */
List<Log> outputLogs = new ArrayList<>();
persistence.getLogs("test-p1", 1, outputLogs);
assertEquals(0, outputLogs.size());
assertEquals(0, persistence.countLogs("test-p1"));
} finally {
/* Close. */
// noinspection ThrowFromFinallyBlock
persistence.close();
}
}
use of com.microsoft.appcenter.ingestion.models.LogWithProperties in project mobile-center-sdk-android by Microsoft.
the class DatabasePersistenceAndroidTest method putLargeLogFails.
@Test
public void putLargeLogFails() {
/* Initialize database persistence. */
String path = Constants.FILES_PATH;
Constants.FILES_PATH = null;
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 and persist. */
LogWithProperties log = AndroidTestUtils.generateMockLog();
int size = 2 * 1024 * 1024;
StringBuilder largeValue = new StringBuilder(size);
for (int i = 0; i < size; i++) {
largeValue.append("x");
}
Map<String, String> properties = new HashMap<>();
properties.put("key", largeValue.toString());
log.setProperties(properties);
persistence.putLog(log, "test-p1", NORMAL);
fail("putLog was expected to fail");
} catch (Persistence.PersistenceException e) {
assertTrue(e.getCause() instanceof IOException);
/* Make sure database entry has been removed. */
assertEquals(0, persistence.countLogs("test-p1"));
} finally {
persistence.close();
/* Restore path. */
Constants.FILES_PATH = path;
}
}
Aggregations