Skip to content

Commit ce89c66

Browse files
committed
#80 ignore additional collections as they may be read only
1 parent ac65cd6 commit ce89c66

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/main/java/com/arangodb/springframework/transaction/ArangoTransactionObject.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.apache.commons.logging.Log;
88
import org.apache.commons.logging.LogFactory;
99
import org.springframework.lang.Nullable;
10-
import org.springframework.transaction.IllegalTransactionStateException;
1110
import org.springframework.transaction.TransactionDefinition;
1211
import org.springframework.transaction.interceptor.TransactionAttribute;
1312
import org.springframework.transaction.support.SmartTransactionObject;
@@ -104,15 +103,16 @@ public String toString() {
104103

105104
private void addCollections(Collection<String> collections) {
106105
if (resource.getStreamTransactionId() != null) {
107-
if (!resource.getCollectionNames().containsAll(collections)) {
106+
if (!resource.getCollectionNames().containsAll(collections) && logger.isDebugEnabled()) {
108107
Set<String> additional = new HashSet<>(collections);
109108
additional.removeAll(resource.getCollectionNames());
110-
throw new IllegalTransactionStateException("Stream transaction already started on collections " + resource.getCollectionNames() + ", no additional collections allowed: " + additional);
109+
logger.debug("Stream transaction already started on collections " + resource.getCollectionNames() + ", assuming additional collections are read only: " + additional);
111110
}
111+
} else {
112+
Set<String> all = new HashSet<>(resource.getCollectionNames());
113+
all.addAll(collections);
114+
resource.setCollectionNames(all);
112115
}
113-
HashSet<String> all = new HashSet<>(resource.getCollectionNames());
114-
all.addAll(collections);
115-
resource.setCollectionNames(all);
116116
}
117117

118118
private boolean isStatus(StreamTransactionStatus status) {

src/test/java/com/arangodb/springframework/transaction/ArangoTransactionManagerTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import static org.hamcrest.MatcherAssert.assertThat;
3333
import static org.hamcrest.Matchers.empty;
3434
import static org.hamcrest.Matchers.is;
35+
import static org.hamcrest.Matchers.hasItem;
3536
import static org.hamcrest.Matchers.hasItems;
37+
import static org.hamcrest.Matchers.not;
3638
import static org.hamcrest.Matchers.nullValue;
3739
import static org.mockito.ArgumentMatchers.any;
3840
import static org.mockito.Mockito.when;
@@ -163,14 +165,16 @@ public void getTransactionWithMultipleBridgeCallsWorksForKnownCollections() {
163165
assertThat(collections.getWrite(), hasItems("baz", "foo"));
164166
}
165167

166-
@Test(expected = IllegalTransactionStateException.class)
167-
public void getTransactionWithMultipleBridgeCallsFailsForAdditionalCollection() {
168+
@Test
169+
public void getTransactionWithMultipleBridgeCallsIgnoresAdditionalCollections() {
168170
DefaultTransactionAttribute definition = new DefaultTransactionAttribute();
169-
definition.setLabels(Collections.singleton("baz"));
171+
definition.setLabels(Collections.singleton("bar"));
170172
definition.setTimeout(20);
171-
underTest.getTransaction(definition);
173+
TransactionStatus state = underTest.getTransaction(definition);
172174
beginTransaction("123", "foo");
173-
beginPassed.getValue().apply(Collections.singletonList("bar"));
175+
beginPassed.getValue().apply(Collections.singletonList("baz"));
176+
assertThat(getTransactionObject(state).getResource().getCollectionNames(), hasItems("foo", "bar"));
177+
assertThat(getTransactionObject(state).getResource().getCollectionNames(), not(hasItem("baz")));
174178
}
175179

176180
@Test(expected = InvalidIsolationLevelException.class)

0 commit comments

Comments
 (0)