Skip to content

Commit

Permalink
Merge branch 'main' into AMP-101721/catch_all_exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
izaaz committed Jun 11, 2024
2 parents 5320573 + c4b80ff commit 54087fa
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
needs: [authorize]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'zulu'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'zulu'
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [2.40.1](https://github.com/amplitude/Amplitude-Android/compare/v2.40.0...v2.40.1) (2024-04-17)


### Bug Fixes

* always run middleware flush on updateServer ([#400](https://github.com/amplitude/Amplitude-Android/issues/400)) ([fbee357](https://github.com/amplitude/Amplitude-Android/commit/fbee357d6ba9eb540101cf09393f7eebafdfd49d))

# [2.40.0](https://github.com/amplitude/Amplitude-Android/compare/v2.39.9...v2.40.0) (2024-04-17)


### Features

* middleware session replay integration ([#399](https://github.com/amplitude/Amplitude-Android/issues/399)) ([28bbbe6](https://github.com/amplitude/Amplitude-Android/commit/28bbbe6ad2d0a0fe6424645e6105ecb8c2be7a4f))

## [2.39.9](https://github.com/amplitude/Amplitude-Android/compare/v2.39.8...v2.39.9) (2024-02-27)


Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARTIFACT_VERSION=2.39.9
ARTIFACT_VERSION=2.40.1
ARTIFACT_GROUP=com.amplitude

POM_PACKAGING=aar
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/amplitude/api/AmplitudeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ public void run() {
return this;
}

public Boolean getOptOut() {
return optOut;
}

/**
* Library name is default as `amplitude-android`.
* Notice: You will only want to set it when following conditions are met.
Expand Down Expand Up @@ -2154,6 +2158,9 @@ protected void updateServer(boolean limit) {
return;
}

// Flush middleware
middlewareRunner.flush();

// if returning out of this block, always be sure to set uploadingCurrently to false!!
if (!uploadingCurrently.getAndSet(true)) {
long totalEventCount = dbHelper.getTotalEventCount();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/amplitude/api/MiddlewareExtended.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.amplitude.api;

interface MiddlewareExtended extends Middleware {
void flush();
}
8 changes: 8 additions & 0 deletions src/main/java/com/amplitude/api/MiddlewareRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public void run(MiddlewarePayload payload, MiddlewareNext next) {
List<Middleware> middlewareList = new ArrayList<>(this.middlewares);
runMiddlewares(middlewareList, payload, next);
}

void flush() {
for (Middleware middleware : middlewares) {
if (middleware instanceof MiddlewareExtended) {
((MiddlewareExtended) middleware).flush();
}
}
}
}
27 changes: 27 additions & 0 deletions src/test/java/com/amplitude/api/MiddlewareRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.concurrent.atomic.AtomicInteger;

@RunWith(AndroidJUnit4.class)
@Config(manifest= Config.NONE)
public class MiddlewareRunnerTest {
Expand Down Expand Up @@ -79,4 +81,29 @@ public void run(MiddlewarePayload payload, MiddlewareNext next) {
assertEquals(event.getString("user_id"), middlewareUser);
}

@Test
public void testMiddlewareFlush() throws JSONException {
AtomicInteger runCount = new AtomicInteger(0);
AtomicInteger flushCount = new AtomicInteger(0);

MiddlewareExtended flushMiddleware = new MiddlewareExtended() {
@Override
public void run(MiddlewarePayload payload, MiddlewareNext next) {
runCount.incrementAndGet();
}

@Override
public void flush() {
flushCount.incrementAndGet();
}
};

middlewareRunner.add(flushMiddleware);

middlewareRunner.flush();

assertEquals(flushCount.get(), 1);
assertEquals(runCount.get(), 0);
}

}

0 comments on commit 54087fa

Please sign in to comment.