Search in sources :

Example 6 with StringUtils.repeat

use of org.apache.commons.lang3.StringUtils.repeat in project reactor-netty by reactor.

the class DefaultPooledConnectionProviderTest method connectionReleasedOnRedirect.

@Test
void connectionReleasedOnRedirect() throws Exception {
    String redirectedContent = StringUtils.repeat("a", 10000);
    disposableServer = createServer().host("localhost").route(r -> r.get("/1", (req, res) -> res.status(HttpResponseStatus.FOUND).header(HttpHeaderNames.LOCATION, "/2").sendString(Flux.just(redirectedContent, redirectedContent))).get("/2", (req, res) -> res.status(200).sendString(Mono.just("OK")))).bindNow();
    CountDownLatch latch = new CountDownLatch(2);
    DefaultPooledConnectionProvider provider = (DefaultPooledConnectionProvider) ConnectionProvider.create("connectionReleasedOnRedirect", 1);
    String response = createClient(provider, disposableServer::address).followRedirect(true).observe((conn, state) -> {
        if (ConnectionObserver.State.RELEASED == state) {
            latch.countDown();
        }
    }).get().uri("/1").responseContent().aggregate().asString().block(Duration.ofSeconds(30));
    assertThat(response).isEqualTo("OK");
    assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
    provider.channelPools.forEach((k, v) -> assertThat(v.metrics().acquiredSize()).isEqualTo(0));
    provider.disposeLater().block(Duration.ofSeconds(30));
}
Also used : StepVerifier(reactor.test.StepVerifier) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) SocketAddress(java.net.SocketAddress) PoolShutdownException(reactor.netty.internal.shaded.reactor.pool.PoolShutdownException) HttpProtocol(reactor.netty.http.HttpProtocol) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) BaseHttpTest(reactor.netty.BaseHttpTest) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ConnectionObserver(reactor.netty.ConnectionObserver) ChannelPromise(io.netty.channel.ChannelPromise) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ByteBufMono(reactor.netty.ByteBufMono) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) InstrumentedPool(reactor.netty.internal.shaded.reactor.pool.InstrumentedPool) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) Signal(reactor.core.publisher.Signal) CertificateException(java.security.cert.CertificateException) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) CountDownLatch(java.util.concurrent.CountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HttpServer(reactor.netty.http.server.HttpServer) SSLException(javax.net.ssl.SSLException) List(java.util.List) SslProvider(io.netty.handler.ssl.SslProvider) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) HttpClient(reactor.netty.http.client.HttpClient) CountDownLatch(java.util.concurrent.CountDownLatch) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with StringUtils.repeat

use of org.apache.commons.lang3.StringUtils.repeat in project Wizardry by TeamWizardry.

the class ComponentSpellRecipe method components.

public static List<PaginationContext> components(GuiBook book) {
    List<PaginationContext> contexts = Lists.newArrayList();
    if (book.getBookItemStack().isEmpty())
        return contexts;
    ItemStack bookStack = book.getBookItemStack();
    if (!NBTHelper.getBoolean(bookStack, "has_spell", false))
        return contexts;
    NBTTagList moduleList = NBTHelper.getList(bookStack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
    if (moduleList == null)
        return contexts;
    List<List<ModuleInstance>> spellModules = SpellUtils.deserializeModuleList(moduleList);
    List<ItemStack> spellItems = SpellUtils.getSpellItems(spellModules);
    spellModules = SpellUtils.getEssentialModules(spellModules);
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    int widthOfSpace = fr.getStringWidth(" ");
    StringBuilder builder = new StringBuilder(LibrarianLib.PROXY.translate("wizardry.book.spell_recipe_structure") + "\n");
    for (List<ModuleInstance> spellModuleList : spellModules) {
        String margin = null;
        for (ModuleInstance module : spellModuleList) {
            if (margin == null) {
                margin = " - ";
                builder.append(margin).append(module.getReadableName()).append("\n");
            } else {
                int realLength = fr.getStringWidth(margin);
                int nbOfSpace = MathHelper.clamp(realLength / widthOfSpace, 0, 17);
                margin = StringUtils.repeat(" ", nbOfSpace) + "|_ ";
                builder.append(margin).append(module.getReadableName()).append("\n");
                if (nbOfSpace >= 16) {
                    builder.append("   ________________|").append("\n");
                    margin = "   ";
                }
            }
        }
    }
    String[] lines = builder.toString().split("\n");
    StringBuilder pageChunk = new StringBuilder();
    int count = 0;
    for (String line : lines) {
        pageChunk.append(line).append("\n");
        if (++count >= 16) {
            count = 0;
            pageFromString(book, contexts, pageChunk);
            pageChunk = new StringBuilder();
        }
    }
    if (count != 0)
        pageFromString(book, contexts, pageChunk);
    Consumer<ComponentVoid> applier = component -> {
    };
    for (int i = 0; i < spellItems.size(); i++) {
        ItemStack stack = spellItems.get(i);
        int index = i;
        applier = applier.andThen(component -> {
            ComponentStack componentStack = new ComponentStack((index % 4) * 32, (index / 4) * 16);
            componentStack.getStack().setValue(stack);
            component.add(componentStack);
            if (index != spellItems.size() - 1 && (index % 4) < 3) {
                ComponentSprite nextItem = new ComponentSprite(book.getHomeSprite(), 32 + (index % 4) * 32, (index / 4) * 16 + 13, 16, 8);
                nextItem.getColor().setValue(book.getBook().getHighlightColor());
                nextItem.getTransform().setRotate(Math.toRadians(180));
                component.add(nextItem);
            }
        });
        if ((index / 4) >= 9) {
            Consumer<ComponentVoid> spellApplier = applier;
            contexts.add(new PaginationContext(() -> {
                ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
                spellApplier.accept(component);
                return component;
            }));
            applier = component -> {
            };
        }
    }
    Consumer<ComponentVoid> spellApplier = applier;
    contexts.add(new PaginationContext(() -> {
        ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
        spellApplier.accept(component);
        return component;
    }));
    return contexts;
}
Also used : ComponentStack(com.teamwizardry.librarianlib.features.gui.components.ComponentStack) IBookGui(com.teamwizardry.librarianlib.features.gui.provided.book.IBookGui) LibrarianLib(com.teamwizardry.librarianlib.core.LibrarianLib) StringUtils(org.apache.commons.lang3.StringUtils) ComponentVoid(com.teamwizardry.librarianlib.features.gui.components.ComponentVoid) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) SpellUtils(com.teamwizardry.wizardry.api.spell.SpellUtils) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) PaginationContext(com.teamwizardry.librarianlib.features.gui.provided.book.context.PaginationContext) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Bookmark(com.teamwizardry.librarianlib.features.gui.provided.book.context.Bookmark) FontRenderer(net.minecraft.client.gui.FontRenderer) Book(com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.book.Book) IBookElement(com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.IBookElement) MathHelper(net.minecraft.util.math.MathHelper) NBTHelper(com.teamwizardry.librarianlib.features.helpers.NBTHelper) ComponentText(com.teamwizardry.librarianlib.features.gui.components.ComponentText) NBTConstants(com.teamwizardry.wizardry.api.NBTConstants) NotNull(org.jetbrains.annotations.NotNull) ComponentStack(com.teamwizardry.librarianlib.features.gui.components.ComponentStack) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) PaginationContext(com.teamwizardry.librarianlib.features.gui.provided.book.context.PaginationContext) ComponentVoid(com.teamwizardry.librarianlib.features.gui.components.ComponentVoid) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance)

Aggregations

List (java.util.List)6 StringUtils (org.apache.commons.lang3.StringUtils)6 DetectOption (com.blackducksoftware.integration.hub.detect.help.DetectOption)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 DetectConfiguration (com.blackducksoftware.integration.hub.detect.DetectConfiguration)1 DetectInfo (com.blackducksoftware.integration.hub.detect.DetectInfo)1 ReportWriter (com.blackducksoftware.integration.hub.detect.workflow.report.writer.ReportWriter)1 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)1 Holder (com.evolveum.midpoint.util.Holder)1 KeyValueTreeNode (com.evolveum.midpoint.util.KeyValueTreeNode)1 TreeNode (com.evolveum.midpoint.util.TreeNode)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 AceEditor (com.evolveum.midpoint.web.component.AceEditor)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)1 CachesStateInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachesStateInformationType)1 ComponentSizeInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ComponentSizeInformationType)1 SingleCacheStateInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SingleCacheStateInformationType)1