/** * Copyright 2016 Yahoo Inc. * * Licensed 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 com.yahoo.pulsar.broker.service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.yahoo.pulsar.common.policies.data.ClusterData; import com.yahoo.pulsar.common.policies.data.PropertyAdmin; import com.yahoo.pulsar.broker.PulsarService; import com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest; /** */ public abstract class BrokerTestBase extends MockedPulsarServiceBaseTest { protected static final int ASYNC_EVENT_COMPLETION_WAIT = 100; protected PulsarService getPulsar() { return pulsar; } public void baseSetup() throws Exception { super.internalSetup(); admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString())); admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("use"))); admin.namespaces().createNamespace("prop/use/ns-abc"); } void rolloverPerIntervalStats() { try { pulsar.getExecutor().submit(() -> pulsar.getBrokerService().updateRates()).get(); } catch (Exception e) { LOG.error("Stats executor error", e); } } void runGC() { try { pulsar.getExecutor().submit(() -> pulsar.getBrokerService().checkGC(0)).get(); Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT); } catch (Exception e) { LOG.error("GC executor error", e); } } void runMessageExpiryCheck() { try { pulsar.getExecutor().submit(() -> pulsar.getBrokerService().checkMessageExpiry()).get(); Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT); } catch (Exception e) { LOG.error("Error running message expiry check", e); } } private static final Logger LOG = LoggerFactory.getLogger(BrokerTestBase.class); }