All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gatling.javaapi.http.Ws Maven / Gradle / Ivy

There is a newer version: 3.13.1
Show newest version
/*
 * Copyright 2011-2024 GatlingCorp (https://gatling.io)
 *
 * 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 io.gatling.javaapi.http;

import static io.gatling.javaapi.core.internal.Expressions.*;
import static io.gatling.javaapi.http.internal.WsFunctions.*;

import edu.umd.cs.findbugs.annotations.NonNull;
import io.gatling.http.action.ws.WsInboundMessage;
import io.gatling.javaapi.core.ActionBuilder;
import io.gatling.javaapi.core.Session;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * DSL for building WebSocket configurations
 *
 * 

Immutable, so all methods return a new occurrence and leave the original unmodified. */ public final class Ws { private final io.gatling.http.action.ws.Ws wrapped; Ws(final io.gatling.http.action.ws.Ws wrapped) { this.wrapped = wrapped; } /** * Define a custom WebSocket name so multiple WebSockets for the same virtual users don't conflict * * @param wsName the name, expressed as a Gatling Expression Language String * @return a new Ws instance */ @NonNull public Ws wsName(@NonNull String wsName) { return new Ws(wrapped.wsName(toStringExpression(wsName))); } /** * Define a custom WebSocket name so multiple WebSockets for the same virtual users don't conflict * * @param wsName the name, expressed as a function * @return a new Ws instance */ @NonNull public Ws wsName(@NonNull Function wsName) { return new Ws(wrapped.wsName(javaFunctionToExpression(wsName))); } /** * Boostrap an action to connect the WebSocket * * @param url the url to connect to, expressed as a Gatling Expression Language String * @return the next DSL step */ @NonNull public WsConnectActionBuilder connect(@NonNull String url) { return new WsConnectActionBuilder(wrapped.connect(toStringExpression(url))); } /** * Boostrap an action to connect the WebSocket * * @param url the url to connect to, expressed as a function * @return the next DSL step */ @NonNull public WsConnectActionBuilder connect(@NonNull Function url) { return new WsConnectActionBuilder(wrapped.connect(javaFunctionToExpression(url))); } /** * Boostrap an action to send a TEXT frame * * @param text the text to send, expressed as a Gatling Expression Language String * @return the next DSL step */ @NonNull public WsSendTextActionBuilder sendText(@NonNull String text) { return new WsSendTextActionBuilder(wrapped.sendText(toStringExpression(text))); } /** * Boostrap an action to send a TEXT frame * * @param text the text to send, expressed as a function * @return the next DSL step */ @NonNull public WsSendTextActionBuilder sendText(@NonNull Function text) { return new WsSendTextActionBuilder(wrapped.sendText(javaFunctionToExpression(text))); } /** * Boostrap an action to send a BINARY frame * * @param bytes the static bytes to send * @return the next DSL step */ @NonNull public WsSendBinaryActionBuilder sendBytes(@NonNull byte[] bytes) { return new WsSendBinaryActionBuilder(wrapped.sendBytes(toStaticValueExpression(bytes))); } /** * Boostrap an action to send a BINARY frame * * @param bytes the bytes to send, expressed as a Gatling Expression Language String * @return the next DSL step */ @NonNull public WsSendBinaryActionBuilder sendBytes(@NonNull String bytes) { return new WsSendBinaryActionBuilder(wrapped.sendBytes(toBytesExpression(bytes))); } /** * Boostrap an action to send a BINARY frame * * @param bytes the bytes to send, expressed as a function * @return the next DSL step */ @NonNull public WsSendBinaryActionBuilder sendBytes(@NonNull Function bytes) { return new WsSendBinaryActionBuilder(wrapped.sendBytes(javaFunctionToExpression(bytes))); } /** * Boostrap an action to send a CLOSE frame with the default 1000 status code * * @return the next DSL step */ @NonNull public ActionBuilder close() { return wrapped::close; } /** * Boostrap an action to send a CLOSE frame with specified status and reason * * @param statusCode the close frame status code * @param reason the close frame reason * @return the next DSL step */ @NonNull public ActionBuilder close(int statusCode, String reason) { return () -> wrapped.close(statusCode, reason); } public static final class Prefix { public static final Prefix INSTANCE = new Prefix(); private Prefix() {} /** * Bootstrap a check on inbound TEXT frames * * @param name the name of the check, expressed as a Gatling Expression Language String * @return the next DSL step */ @NonNull public WsFrameCheck.Text checkTextMessage(@NonNull String name) { return new WsFrameCheck.Text( io.gatling.http.Predef.ws().checkTextMessage(toStringExpression(name))); } /** * Bootstrap a check on inbound TEXT frames * * @param name the name of the check, expressed as a function * @return the next DSL step */ @NonNull public WsFrameCheck.Text checkTextMessage(@NonNull Function name) { return new WsFrameCheck.Text( io.gatling.http.Predef.ws().checkTextMessage(javaFunctionToExpression(name))); } /** * Bootstrap a check on inbound BINARY frames * * @param name the name of the check, expressed as a Gatling Expression Language String * @return the next DSL step */ @NonNull public WsFrameCheck.Binary checkBinaryMessage(@NonNull String name) { return new WsFrameCheck.Binary( io.gatling.http.Predef.ws().checkBinaryMessage(toStringExpression(name))); } /** * Bootstrap a check on inbound BINARY frames * * @param name the name of the check, expressed as a function * @return the next DSL step */ @NonNull public WsFrameCheck.Binary checkBinaryMessage(@NonNull Function name) { return new WsFrameCheck.Binary( io.gatling.http.Predef.ws().checkBinaryMessage(javaFunctionToExpression(name))); } /** * Process the currently buffered inbound WebSocket messages and empty the buffer * * @param f the function to process the buffered messages * @return an ActionBuilder */ public ActionBuilder processUnmatchedMessages( BiFunction, Session, Session> f) { return () -> io.gatling.http.Predef.ws() .processUnmatchedMessages(javaProcessUnmatchedMessagesBiFunctionToExpression(f)); } /** * Process the currently buffered inbound WebSocket messages and empty the buffer * * @param wsName the name of the WebSocket, expressed as a Gatling Expression Language String * @param f the function to process the buffered messages * @return an ActionBuilder */ public ActionBuilder processUnmatchedMessages( String wsName, BiFunction, Session, Session> f) { return () -> io.gatling.http.Predef.ws() .processUnmatchedMessages( toStringExpression(wsName), javaProcessUnmatchedMessagesBiFunctionToExpression(f)); } /** * Process the currently buffered inbound WebSocket messages and empty the buffer * * @param wsName the name of the WebSocket, expressed as a function * @param f the function to process the buffered messages * @return an ActionBuilder */ public ActionBuilder processUnmatchedMessages( Function wsName, BiFunction, Session, Session> f) { return () -> io.gatling.http.Predef.ws() .processUnmatchedMessages( javaFunctionToExpression(wsName), javaProcessUnmatchedMessagesBiFunctionToExpression(f)); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy