-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] [ml] Fix the incorrect total size if use ML interceptor (#19404)
(cherry picked from commit 33f40f6)
- Loading branch information
1 parent
d4f8c40
commit a0a9eb5
Showing
4 changed files
with
139 additions
and
5 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
85 changes: 85 additions & 0 deletions
85
...er/src/test/java/org/apache/bookkeeper/mledger/impl/MangedLedgerInterceptorImplTest2.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,85 @@ | ||
/** | ||
* 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.bookkeeper.mledger.impl; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.apache.pulsar.broker.intercept.MangedLedgerInterceptorImplTest.TestPayloadProcessor; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.bookkeeper.client.LedgerHandle; | ||
import org.apache.bookkeeper.mledger.ManagedLedgerConfig; | ||
import org.apache.bookkeeper.mledger.intercept.ManagedLedgerInterceptor; | ||
import org.apache.bookkeeper.test.MockedBookKeeperTestCase; | ||
import org.apache.pulsar.broker.intercept.ManagedLedgerInterceptorImpl; | ||
import org.apache.pulsar.broker.intercept.MangedLedgerInterceptorImplTest; | ||
import org.apache.pulsar.common.intercept.ManagedLedgerPayloadProcessor; | ||
import org.awaitility.Awaitility; | ||
import org.testng.annotations.Test; | ||
|
||
/*** | ||
* Differ to {@link MangedLedgerInterceptorImplTest}, this test can call {@link ManagedLedgerImpl}'s methods modified | ||
* by "default". | ||
*/ | ||
@Slf4j | ||
@Test(groups = "broker") | ||
public class MangedLedgerInterceptorImplTest2 extends MockedBookKeeperTestCase { | ||
|
||
private void switchLedgerManually(ManagedLedgerImpl ledger){ | ||
LedgerHandle originalLedgerHandle = ledger.currentLedger; | ||
ledger.ledgerClosed(ledger.currentLedger); | ||
ledger.createLedgerAfterClosed(); | ||
Awaitility.await().until(() -> { | ||
return ledger.state == ManagedLedgerImpl.State.LedgerOpened && ledger.currentLedger != originalLedgerHandle; | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCurrentLedgerSizeCorrectIfHasInterceptor() throws Exception { | ||
final String mlName = "ml1"; | ||
final String cursorName = "cursor1"; | ||
|
||
// Registry interceptor. | ||
ManagedLedgerConfig config = new ManagedLedgerConfig(); | ||
Set<ManagedLedgerPayloadProcessor> processors = new HashSet(); | ||
processors.add(new TestPayloadProcessor()); | ||
ManagedLedgerInterceptor interceptor = new ManagedLedgerInterceptorImpl(new HashSet(), processors); | ||
config.setManagedLedgerInterceptor(interceptor); | ||
config.setMaxEntriesPerLedger(100); | ||
|
||
// Add one entry. | ||
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open(mlName, config); | ||
ManagedCursorImpl cursor = (ManagedCursorImpl) ledger.openCursor(cursorName); | ||
ledger.addEntry(new byte[1]); | ||
|
||
// Mark "currentLedgerSize" and switch ledger. | ||
long currentLedgerSize = ledger.getCurrentLedgerSize(); | ||
switchLedgerManually(ledger); | ||
|
||
// verify. | ||
assertEquals(currentLedgerSize, MangedLedgerInterceptorImplTest.calculatePreciseSize(ledger)); | ||
|
||
// cleanup. | ||
cursor.close(); | ||
ledger.close(); | ||
factory.getEntryCacheManager().clear(); | ||
factory.shutdown(); | ||
config.setManagedLedgerInterceptor(null); | ||
} | ||
} |
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