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));
}
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;
}
Aggregations