From 1fef4c3d2e48e8d6d00e9c91c499b8af8a166444 Mon Sep 17 00:00:00 2001 From: bgamard Date: Mon, 25 Jan 2021 21:31:14 +0100 Subject: [PATCH] next dev iteration + cleanup stress project --- docs-core/pom.xml | 2 +- docs-stress/pom.xml | 81 ----------- .../java/com/sismics/docs/stress/Main.java | 135 ------------------ docs-stress/src/main/resources/empty.png | Bin 921 -> 0 bytes .../src/main/resources/log4j.properties | 6 - docs-web-common/pom.xml | 2 +- docs-web/pom.xml | 2 +- pom.xml | 2 +- 8 files changed, 4 insertions(+), 226 deletions(-) delete mode 100644 docs-stress/pom.xml delete mode 100644 docs-stress/src/main/java/com/sismics/docs/stress/Main.java delete mode 100644 docs-stress/src/main/resources/empty.png delete mode 100644 docs-stress/src/main/resources/log4j.properties diff --git a/docs-core/pom.xml b/docs-core/pom.xml index 956decc5..f26794e2 100644 --- a/docs-core/pom.xml +++ b/docs-core/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.9 + 1.10-SNAPSHOT .. diff --git a/docs-stress/pom.xml b/docs-stress/pom.xml deleted file mode 100644 index 75e12807..00000000 --- a/docs-stress/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - com.sismics.docs - docs-parent - 1.9 - .. - - - 4.0.0 - docs-stress - jar - Docs Stress - - - - - org.glassfish.jersey.core - jersey-client - - - - org.glassfish.jersey.media - jersey-media-multipart - - - - - com.sismics.docs - docs-web-common - - - - com.sismics.docs - docs-web-common - test-jar - - - - - com.google.guava - guava - - - - log4j - log4j - - - - org.slf4j - slf4j-log4j12 - - - - org.slf4j - slf4j-api - - - - org.slf4j - jcl-over-slf4j - - - - junit - junit - - - - - - - - src/main/resources - - - - diff --git a/docs-stress/src/main/java/com/sismics/docs/stress/Main.java b/docs-stress/src/main/java/com/sismics/docs/stress/Main.java deleted file mode 100644 index 3a7f78fd..00000000 --- a/docs-stress/src/main/java/com/sismics/docs/stress/Main.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.sismics.docs.stress; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.google.common.io.Resources; -import com.sismics.docs.rest.util.ClientUtil; -import com.sismics.util.filter.TokenBasedSecurityFilter; -import org.glassfish.jersey.client.ClientResponse; -import org.glassfish.jersey.media.multipart.FormDataMultiPart; -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart; -import org.junit.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.json.JsonObject; -import javax.ws.rs.client.*; -import javax.ws.rs.core.Form; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response.Status; -import java.io.InputStream; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -/** - * Stress app for Teedy. - * - * @author bgamard - */ -public class Main { - /** - * Logger. - */ - private static final Logger log = LoggerFactory.getLogger(Main.class); - - private static final String API_URL = "http://localhost:9999/docs-web/api/"; - private static final int USER_COUNT = 50; - private static final int DOCUMENT_PER_USER_COUNT = 2000; - private static final int TAG_PER_USER_COUNT = 20; - private static final int FILE_PER_DOCUMENT_COUNT = 10; - - private static Client client = ClientBuilder.newClient(); - - private static Set userSet = Sets.newHashSet(); - - /** - * Entry point. - * - * @param args Args - * @throws Exception - */ - public static void main(String[] args) throws Exception { - log.info("Starting stress test..."); - - WebTarget resource = client.target(API_URL); - ClientUtil clientUtil = new ClientUtil(resource); - - // Create users - for (int i = 0; i < USER_COUNT; i++) { - String username = generateString(); - clientUtil.createUser(username); - userSet.add(new User(username, (clientUtil.login(username)))); - log.info("Created user " + (i + 1) + "/" + USER_COUNT); - } - - // Create tags for each user - int tagCreatedCount = 1; - for (User user : userSet) { - Invocation.Builder tagResource = resource.path("/tag").request() - .cookie(TokenBasedSecurityFilter.COOKIE_NAME, user.authToken); - - for (int j = 0; j < TAG_PER_USER_COUNT; j++) { - Form form = new Form(); - String name = generateString(); - form.param("name", name); - form.param("color", "#ff0000"); - JsonObject json = tagResource.put(Entity.form(form), JsonObject.class); - user.tagList.add(json.getString("id")); - log.info("Created tag " + (tagCreatedCount++) + "/" + TAG_PER_USER_COUNT * USER_COUNT); - } - } - - // Create documents for each user - int documentCreatedCount = 1; - for (User user : userSet) { - for (int i = 0; i < DOCUMENT_PER_USER_COUNT; i++) { - long createDate = new Date().getTime(); - Form form = new Form() - .param("title", generateString()) - .param("description", generateString()) - .param("tags", user.tagList.get(ThreadLocalRandom.current().nextInt(user.tagList.size()))) // Random tag - .param("language", "eng") - .param("create_date", Long.toString(createDate)); - JsonObject json = resource.path("/document").request() - .cookie(TokenBasedSecurityFilter.COOKIE_NAME, user.authToken) - .put(Entity.form(form), JsonObject.class); - String documentId = json.getString("id"); - log.info("Created document " + (documentCreatedCount++) + "/" + DOCUMENT_PER_USER_COUNT * USER_COUNT + " for user: " + user.username); - - // Add files for each document - for (int j = 0; j < FILE_PER_DOCUMENT_COUNT; j++) { - try (InputStream is = Resources.getResource("empty.png").openStream()) { - StreamDataBodyPart streamDataBodyPart = new StreamDataBodyPart("file", is, "empty.png"); - @SuppressWarnings("resource") - ClientResponse response = resource - .register(MultiPartFeature.class) - .path("/file").request() - .cookie(TokenBasedSecurityFilter.COOKIE_NAME, user.authToken) - .put(Entity.entity(new FormDataMultiPart().field("id", documentId).bodyPart(streamDataBodyPart), - MediaType.MULTIPART_FORM_DATA_TYPE), ClientResponse.class); - Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus())); - } - } - } - } - } - - private static String generateString() { - return UUID.randomUUID().toString().replace("-", ""); - } - - private static class User { - String username; - List tagList = Lists.newArrayList(); - String authToken; - - User(String username, String authToken) { - this.username = username; - this.authToken = authToken; - } - } -} diff --git a/docs-stress/src/main/resources/empty.png b/docs-stress/src/main/resources/empty.png deleted file mode 100644 index cee8159108c0612fb5980313879099e4e546df96..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 921 zcmaJ=%Wl&^6m_XoL8Xc{tVZs##GY|*9FJl`Vka~bj-n(|v&69{jg{JC#uMyhh1hk+ znty;FK!P>Dz=AJ8V$Y_G(>P^8u;h8^oO92;bLV={e{pjB_*jyplis;A6!Ssx-@hlu z_u1%&m>%)YgpcTqXC5O`E1**XdXaZYhQte2ufLIoBprfqJmC}fCH85gcm+nuqeQSJ zsnN_6&tDJ@rsOh=E&12yuQCV&OTN%u=q5Iqhv#cXM(h6AUoU(!kekmyBgaA@BHROc zbQPyKx8#j37VF|zmB9wW7nXc$YT^!nO&I~Y0xLeOK~O^qsy;Og;|b6pf-2Nhq*aiC zs~Uz7Y(H5>Lz2=Z^Tox@PK!_pwi)p_Wn)UO$|?@#l+$!h6JU>Ya1q7<&C(6pb#X6FxflDS z=UB4fD`6PmTDxnYmebN9auDk1by(NUwq13qNDPKuavka~BNFqH8{Bc*d$~m;M2U#( z5Ei~6L6^}8Y!b%delPXCdRuO=-;24Is|qt}ajkz{b9p3sr&#WqR%~`{Ph!#QOf>a_ rpI<(R2l24yw8r`O>F=AH=JU4)($UeObau@@7LTRZ={uj=uipIuIffaM diff --git a/docs-stress/src/main/resources/log4j.properties b/docs-stress/src/main/resources/log4j.properties deleted file mode 100644 index d7ea887b..00000000 --- a/docs-stress/src/main/resources/log4j.properties +++ /dev/null @@ -1,6 +0,0 @@ -log4j.rootCategory=WARN, CONSOLE -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %p %l %m %n - -log4j.logger.com.sismics=DEBUG diff --git a/docs-web-common/pom.xml b/docs-web-common/pom.xml index 903e2673..d6684215 100644 --- a/docs-web-common/pom.xml +++ b/docs-web-common/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.9 + 1.10-SNAPSHOT .. diff --git a/docs-web/pom.xml b/docs-web/pom.xml index dde15638..78699765 100644 --- a/docs-web/pom.xml +++ b/docs-web/pom.xml @@ -5,7 +5,7 @@ com.sismics.docs docs-parent - 1.9 + 1.10-SNAPSHOT .. diff --git a/pom.xml b/pom.xml index fa9a5290..c3d0bd6c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sismics.docs docs-parent pom - 1.9 + 1.10-SNAPSHOT Docs Parent