-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARTEMIS-5308 Replicate journal after local checks
Say there's an issue with the record on the local journal, it would fail on the local journal before reaching the replica.
- Loading branch information
1 parent
00f69a1
commit 6dd8837
Showing
4 changed files
with
161 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ver/src/test/java/org/apache/activemq/artemis/core/replication/ReplicatedJournalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.activemq.artemis.core.replication; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.apache.activemq.artemis.core.journal.Journal; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ReplicatedJournalTest { | ||
|
||
private static final int NO_INVOCATION = 0; | ||
private static final int JOURNAL_INVOCATION = 1; | ||
private static final int REPLICA_INVOCATION = 2; | ||
|
||
@Test | ||
public void testAppendInvocationOrder() throws Exception { | ||
AtomicInteger firstInvocation = new AtomicInteger(NO_INVOCATION); | ||
|
||
Journal mockJournal = Mockito.mock(Journal.class, invocationOnMock -> { | ||
if (invocationOnMock.getMethod().getName().startsWith("append") || | ||
invocationOnMock.getMethod().getName().startsWith("tryAppend")) { | ||
firstInvocation.compareAndSet(NO_INVOCATION, JOURNAL_INVOCATION); | ||
} | ||
return null; | ||
}); | ||
|
||
ReplicationManager replicationManager = Mockito.mock(ReplicationManager.class, invocationOnMock -> { | ||
if (invocationOnMock.getMethod().getName().startsWith("append") || | ||
invocationOnMock.getMethod().getName().startsWith("tryAppend")) { | ||
firstInvocation.compareAndSet(NO_INVOCATION, REPLICA_INVOCATION); | ||
} | ||
return null; | ||
}); | ||
|
||
ReplicatedJournal replicatedJournal = new ReplicatedJournal((byte)0, mockJournal, replicationManager); | ||
|
||
for (Method method : ReplicatedJournal.class.getDeclaredMethods()) { | ||
if (method.getName().startsWith("append") || | ||
method.getName().startsWith("tryAppend")) { | ||
List<Object> args = new ArrayList<>(); | ||
for (Class parameterType : method.getParameterTypes()) { | ||
if (boolean.class.equals(parameterType)) { | ||
args.add(false); | ||
} else if (byte.class.equals(parameterType)) { | ||
args.add((byte)0); | ||
} else if (long.class.equals(parameterType)) { | ||
args.add((long)0); | ||
} else { | ||
args.add(null); | ||
} | ||
} | ||
|
||
method.invoke(replicatedJournal, args.toArray()); | ||
|
||
assertEquals(JOURNAL_INVOCATION, firstInvocation.get(), method.toString()); | ||
|
||
firstInvocation.set(NO_INVOCATION); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters