Skip to content

Commit

Permalink
Merge 7d07d85 into 99f8d2c
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy authored Apr 29, 2021
2 parents 99f8d2c + 7d07d85 commit 05d795f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
*
*/

import io.invertase.firebase.common.ReactNativeFirebaseJSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
Expand All @@ -36,7 +35,7 @@ public class TaskExecutorService {
private final String name;
private final int maximumPoolSize;
private final int keepAliveSeconds;
private static Map<String, ExecutorService> executors = new HashMap<>();
private static final Map<String, ExecutorService> executors = new HashMap<>();

TaskExecutorService(String name) {
this.name = name;
Expand Down Expand Up @@ -73,39 +72,39 @@ public ExecutorService getExecutor(boolean isTransactional, String identifier) {
}

private ExecutorService getNewExecutor(boolean isTransactional) {
if (isTransactional == true) {
if (isTransactional) {
return Executors.newSingleThreadExecutor();
} else {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, maximumPoolSize, keepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, maximumPoolSize, keepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<>());
threadPoolExecutor.setRejectedExecutionHandler(executeInFallback);
return threadPoolExecutor;
}
}

private RejectedExecutionHandler executeInFallback = new RejectedExecutionHandler() {
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating()) {
return;
}
ExecutorService fallbackExecutor = getTransactionalExecutor();
fallbackExecutor.execute(r);
};
private final RejectedExecutionHandler executeInFallback = (r, executor) -> {
if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating()) {
return;
}
ExecutorService fallbackExecutor = getTransactionalExecutor();
fallbackExecutor.execute(r);
};

public String getExecutorName(boolean isTransactional, String identifier) {
if (isTransactional == true) {
if (isTransactional) {
return name + "TransactionalExecutor" + identifier;
}
return name + "Executor" + identifier;
}

public void shutdown() {
Set<String> existingExecutorNames = executors.keySet();
for (String executorName : existingExecutorNames) {
if (executorName.startsWith(name) == false) {
existingExecutorNames.remove(executorName);
} else {
removeExecutor(executorName);
synchronized(executors) {
List<String> existingExecutorNames = new ArrayList<>(executors.keySet());
for (String executorName : existingExecutorNames) {
if (!executorName.startsWith(name)) {
executors.remove(executorName);
} else {
removeExecutor(executorName);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/e2e/config.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('config', function () {
});

describe('json', function () {
xit('should read firebase.json data', async function () {
it('should read firebase.json data', async function () {
const jsonData = await NativeModules.RNFBAppModule.jsonGetAll();
jsonData.rnfirebase_json_testing_string.should.equal('abc');
jsonData.rnfirebase_json_testing_boolean_false.should.equal(false);
Expand Down
5 changes: 4 additions & 1 deletion tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ function Root() {
style={{ flex: 1, paddingTop: 20, justifyContent: 'center', alignItems: 'center' }}
>
<Text style={{ fontSize: 25, marginBottom: 30 }}>React Native Firebase</Text>
<Text style={{ fontSize: 25, marginBottom: 30 }}>End-to-End Testing App2</Text>
<Text style={{ fontSize: 25, marginBottom: 30 }}>End-to-End Testing App</Text>
<Button
style={{ flex: 1, marginTop: 20 }}
title={'Test Native Crash Now.'}
onPress={() => {
firebase.crashlytics().crash();
}}
/>
<View testId="spacer" style={{ height: 20 }} />
<Button
style={{ flex: 1, marginTop: 20 }}
title={'Test Javascript Crash Now.'}
onPress={() => {
undefinedVariable.notAFunction();
Expand Down

0 comments on commit 05d795f

Please sign in to comment.