Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;

import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.ERROR;
Expand Down Expand Up @@ -336,7 +337,13 @@ public final void notifyOfCommit(SpiTransaction transaction) {
try {
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, transaction);
postCommit.notifyLocalCache();
backgroundExecutor.execute(postCommit.backgroundNotify());
Runnable backgroundNotify = postCommit.backgroundNotify();
try {
backgroundExecutor.execute(backgroundNotify);
} catch (RejectedExecutionException ex) {
// Preserve notifications when shutdown has stopped the background executor.
backgroundNotify.run();
}
} catch (Exception ex) {
log.log(ERROR, "NotifyOfCommit failed. L2 Cache potentially not notified.", ex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.ebeaninternal.server.transaction;

import io.ebean.BackgroundExecutor;
import io.ebean.cache.ServerCacheNotify;
import io.ebean.config.DatabaseConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.plugin.SpiServer;
import io.ebeaninternal.api.SpiLogManager;
import io.ebeaninternal.api.SpiProfileHandler;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.api.TransactionEvent;
import io.ebeaninternal.server.cluster.ClusterManager;
import io.ebeaninternal.server.core.PersistRequestBean;
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
import io.ebeanservice.docstore.api.DocStoreUpdateProcessor;
import org.junit.jupiter.api.Test;

import java.util.concurrent.RejectedExecutionException;

import static org.mockito.Mockito.*;

class TransactionManagerNotifyOfCommitTest {

@Test
void rejectedSubmission_notifiesListenerSynchronously() {
var executor = mock(BackgroundExecutor.class);
doThrow(new RejectedExecutionException()).when(executor).execute(any(Runnable.class));
var config = new DatabaseConfig();
config.setDatabasePlatform(new DatabasePlatform());
var manager = new TransactionManager(new TransactionManagerOptions(mock(SpiServer.class), true, config,
mock(TransactionScopeManager.class), mock(ClusterManager.class), executor,
mock(DocStoreUpdateProcessor.class), mock(BeanDescriptorManager.class), mock(DataSourceSupplier.class),
mock(SpiProfileHandler.class), mock(SpiLogManager.class), mock(TableModState.class), mock(ServerCacheNotify.class)));
var listener = mock(PersistRequestBean.class);
var event = new TransactionEvent();
event.addListenerNotify(listener);
var transaction = mock(SpiTransaction.class);
when(transaction.event()).thenReturn(event);

manager.notifyOfCommit(transaction);

verify(listener).notifyLocalPersistListener();
}
}
Loading