Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team decided to do a breaking change in getErrorReport #306

Merged
merged 2 commits into from Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,18 @@
package com.microsoft.azure.mobile.analytics.mobile.sasquatch.features;

import android.util.Log;

import com.microsoft.azure.mobile.crashes.Crashes;
import com.microsoft.azure.mobile.crashes.model.ErrorReport;

import static com.microsoft.azure.mobile.sasquatch.activities.MainActivity.LOG_TAG;

public class GetLastSessionErrorReportFeatureTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want to have Test at the end of the class name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a feature test, the one for get last session error report. So it's a get last session error report feature test.


public static void run() {
ErrorReport lastSessionCrashReport = Crashes.getLastSessionCrashReport();
if (lastSessionCrashReport != null) {
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", lastSessionCrashReport.getThrowable());
}
}
}
Expand Up @@ -4,7 +4,6 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AlertDialog;
Expand All @@ -18,6 +17,7 @@

import com.microsoft.azure.mobile.MobileCenter;
import com.microsoft.azure.mobile.analytics.Analytics;
import com.microsoft.azure.mobile.analytics.mobile.sasquatch.features.GetLastSessionErrorReportFeatureTest;
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
import com.microsoft.azure.mobile.crashes.Crashes;
import com.microsoft.azure.mobile.crashes.ErrorAttachments;
Expand All @@ -30,12 +30,10 @@

public class MainActivity extends AppCompatActivity {

public static final String LOG_TAG = "MobileCenterSasquatch";
static final String APP_SECRET = "45d1d9f6-2492-4e68-bd44-7190351eb5f3";
static final String APP_SECRET_KEY = "appSecret";
static final String SERVER_URL_KEY = "serverUrl";

private static final String LOG_TAG = "MobileCenterSasquatch";

static SharedPreferences sSharedPreferences;

@Override
Expand All @@ -55,16 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
MobileCenter.start(getApplication(), getAppSecret(), Analytics.class, Crashes.class);

Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void[] params) {
ErrorReport lastSessionCrashReport = Crashes.getLastSessionCrashReport();
if (lastSessionCrashReport != null) {
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", lastSessionCrashReport.getThrowable());
}
return null;
}
}.execute();
GetLastSessionErrorReportFeatureTest.run();

((TextView) findViewById(R.id.package_name)).setText(String.format(getString(R.string.sdk_source_format), getPackageName().substring(getPackageName().lastIndexOf(".") + 1)));
TestFeatures.initialize(this);
Expand Down
@@ -0,0 +1,25 @@
package com.microsoft.azure.mobile.analytics.mobile.sasquatch.features;

import android.support.annotation.Nullable;
import android.util.Log;

import com.microsoft.azure.mobile.ResultCallback;
import com.microsoft.azure.mobile.crashes.Crashes;
import com.microsoft.azure.mobile.crashes.model.ErrorReport;

import static com.microsoft.azure.mobile.sasquatch.activities.MainActivity.LOG_TAG;

public class GetLastSessionErrorReportFeatureTest {

public static void run() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(@Nullable ErrorReport data) {
if (data != null) {
Log.i(LOG_TAG, "Crashes.getLastSessionCrashReport().getThrowable()=", data.getThrowable());
}
}
});
}
}
Expand Up @@ -148,7 +148,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {

/* Check last session error report. */
assertTrue(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand Down Expand Up @@ -193,7 +193,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Crashes.getInstance().onChannelReady(sContext, channel);
waitForCrashesHandlerTasksToComplete();
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand Down Expand Up @@ -277,7 +277,7 @@ public void run() {
Crashes.unsetInstance();
Crashes.getInstance().onChannelReady(sContext, channel);
waitForCrashesHandlerTasksToComplete();
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand Down
Expand Up @@ -263,14 +263,14 @@ public static boolean hasCrashedInLastSession() {
/**
* Provides information about any available crash report from the last session, if it crashed.
* This method is a synchronous call and blocks caller thread.
* Use {@link #getLastSessionCrashReportAsync(ResultCallback)} for asynchronous call.
* Use {@link #getLastSessionCrashReport(ResultCallback)} for asynchronous call.
*
* @return The crash report from the last session if one was set.
* @see #getLastSessionCrashReportAsync(ResultCallback)
* @see #getLastSessionCrashReport(ResultCallback)
*/
@Nullable
@WorkerThread
public static ErrorReport getLastSessionCrashReport() {
static ErrorReport getLastSessionCrashReport() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, can you call getInstance().getInstanceLastSessionCrashReport() directly from Xamarin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not because it is private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check something before I can answer that.

return getInstance().getInstanceLastSessionCrashReport();
}

Expand All @@ -279,8 +279,8 @@ public static ErrorReport getLastSessionCrashReport() {
*
* @param callback The callback that will receive crash in the last session.
*/
public static void getLastSessionCrashReportAsync(ResultCallback<ErrorReport> callback) {
getInstance().getInstanceLastSessionCrashReportAsync(callback);
public static void getLastSessionCrashReport(ResultCallback<ErrorReport> callback) {
getInstance().getInstanceLastSessionCrashReport(callback);
}

/**
Expand All @@ -306,9 +306,9 @@ private synchronized ErrorReport getInstanceLastSessionCrashReport() {
}

/**
* Implements {@link #getLastSessionCrashReportAsync(ResultCallback)} at instance level.
* Implements {@link #getLastSessionCrashReport(ResultCallback)} at instance level.
*/
private synchronized void getInstanceLastSessionCrashReportAsync(final ResultCallback<ErrorReport> callback) {
private synchronized void getInstanceLastSessionCrashReport(final ResultCallback<ErrorReport> callback) {
if (mCountDownLatch == null || mCountDownLatch.getCount() <= 0)
HandlerUtils.runOnUiThread(new Runnable() {

Expand Down
Expand Up @@ -865,10 +865,10 @@ public void onResult(ErrorReport data) {
}
};

Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
}

@Test
Expand Down Expand Up @@ -911,8 +911,8 @@ public void onResult(ErrorReport data) {
public String answer(InvocationOnMock invocation) throws Throwable {

/* Call twice for multiple listeners during initialize. */
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getLastSessionCrashReport(callback);
return "";
}
});
Expand All @@ -930,7 +930,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {

assertTrue(Crashes.hasCrashedInLastSession());

Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport errorReport) {
Expand All @@ -954,7 +954,7 @@ public void noCrashInLastSessionWhenDisabled() {
Crashes.setEnabled(false);

assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport data) {
Expand Down Expand Up @@ -997,11 +997,11 @@ public void onResult(ErrorReport data) {
* Here the service is enabled by default but we are waiting channel to be ready, simulate that.
*/
assertTrue(Crashes.isEnabled());
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));

assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);

/*
* De-serializing fails twice: processing the log from last time as part of the bulk processing.
Expand All @@ -1019,7 +1019,7 @@ public void crashInLastSessionCorrupted() throws IOException {
when(ErrorLogHelper.getLastErrorLogFile()).thenReturn(file);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
Crashes.getLastSessionCrashReportAsync(new ResultCallback<ErrorReport>() {
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {

@Override
public void onResult(ErrorReport data) {
Expand All @@ -1043,8 +1043,8 @@ public void onResult(ErrorReport data) {
};

/* Call twice for multiple callbacks before initialize. */
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReportAsync(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getLastSessionCrashReport(callback);
Crashes.getInstance().onChannelReady(mock(Context.class), mock(Channel.class));
assertFalse(Crashes.hasCrashedInLastSession());
}
Expand Down