Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][test] Fixed post commit test failure #326

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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 @@ -19,7 +19,7 @@
package org.apache.bookkeeper.mledger.impl;

import static org.testng.Assert.assertEquals;
import static org.apache.pulsar.broker.intercept.MangedLedgerInterceptorImplTest.TestPayloadProcessor;
import static org.apache.pulsar.broker.intercept.ManagedLedgerInterceptorImplTest.TestPayloadProcessor;
import java.util.HashSet;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -28,20 +28,40 @@
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.broker.intercept.ManagedLedgerInterceptorImplTest;
import org.apache.pulsar.common.intercept.ManagedLedgerPayloadProcessor;
import org.awaitility.Awaitility;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/***
* Differ to {@link MangedLedgerInterceptorImplTest}, this test can call {@link ManagedLedgerImpl}'s methods modified
* Differ to {@link ManagedLedgerInterceptorImplTest}, this test can call {@link ManagedLedgerImpl}'s methods modified
* by "default".
*/
@Slf4j
@Test(groups = "broker")
public class MangedLedgerInterceptorImplTest2 extends MockedBookKeeperTestCase {
public class ManagedLedgerInterceptorImplTest2 extends MockedBookKeeperTestCase {

public static void switchLedgerManually(ManagedLedgerImpl ledger){
private ManagedLedgerImpl ledger;


@BeforeMethod
public void setup() throws Exception {
final String mlName = "ml1";

// 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);

// Open the ledger.
ledger = (ManagedLedgerImpl) factory.open(mlName, config);
}

public void switchLedgerManually() {
LedgerHandle originalLedgerHandle = ledger.currentLedger;
ledger.ledgerClosed(ledger.currentLedger);
ledger.createLedgerAfterClosed();
Expand All @@ -52,34 +72,23 @@ public static void switchLedgerManually(ManagedLedgerImpl ledger){

@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);
switchLedgerManually();

// verify.
assertEquals(currentLedgerSize, MangedLedgerInterceptorImplTest.calculatePreciseSize(ledger));
assertEquals(currentLedgerSize, ManagedLedgerInterceptorImplTest.calculatePreciseSize(ledger));

// cleanup.
cursor.close();
ledger.close();
factory.getEntryCacheManager().clear();
factory.shutdown();
config.setManagedLedgerInterceptor(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void setup() throws Exception {
conf.setTlsCertificateFilePath(BROKER_CERT_FILE_PATH);
conf.setTlsKeyFilePath(BROKER_KEY_FILE_PATH);
conf.setNumExecutorThreadPoolSize(5);
conf.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));

super.internalSetup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
import static org.testng.Assert.assertNotNull;

@Test(groups = "broker")
public class MangedLedgerInterceptorImplTest extends MockedBookKeeperTestCase {
private static final Logger log = LoggerFactory.getLogger(MangedLedgerInterceptorImplTest.class);
public class ManagedLedgerInterceptorImplTest extends MockedBookKeeperTestCase {
private static final Logger log = LoggerFactory.getLogger(ManagedLedgerInterceptorImplTest.class);

public static class TestPayloadProcessor implements ManagedLedgerPayloadProcessor {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private ServiceConfiguration brokerConfig() {
config.setLoadManagerClassName(ExtensibleLoadManagerImpl.class.getName());
config.setLoadBalancerDebugModeEnabled(true);
config.setBrokerShutdownTimeoutMs(100);
config.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
return config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected void setup() throws Exception {
config.setBrokerServicePort(Optional.of(0));
config.setWebServicePort(Optional.of(0));
config.setMetadataStoreUrl("zk:localhost:" + zkPort);
config.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
}

@AfterClass
Expand Down
Loading