Creating ChainBuilder via Functional Interface

I want to execute a request based on condition. I’m trying the Functional Interface approach in Java ,
How do I get this running ?

Compile Error:
Bad return type in lambda expression: ChainBuilder cannot be converted to Session

Also in the below code I want to skip the request if, filteredCount==0. How do I do that ?

static Function<Session, ChainBuilder> conditionalFunc =
            session -> session.getInt("filteredCount")>0 
              ? approveJobReqs() : null;  
//>>> How can I skip the request , or use Optional.empty() instead of null ?

public static ChainBuilder checkForApprovals = 
               exec(session -> conditionalFunc.apply(session));

private static ChainBuilder approveJobReqs() {
         return exec(
                http("#{transactionName_2}")
                        .post("/xi/someajax/")                
                        .exec(session -> {
                            .........
                            log.info("Executing"));
                            return session;
                        } );
   }

Wrong way, this can’t work. You should use a doIf block in your scenario.

@slandelle - Could you please provide me a better approach or point me to an example for the same ?
I read some documentation on here, wondering how I can use a functional interface to construct these conditional requests ?

Appreciate your inputs.

As I said, this approach doesn’t work, see Gatling - Scenario

DSL components are merely definitions. They have absolutely no effect when not chained with other DSL components. In particular, you can’t use them in functions.

Thanks @slandelle ! . Just for anyone referring to this in the future, this worked :

scenario("Simulation")
.exec(jobReq.doUpdate)
       .doIf(session -> session.getInt("filteredCount")>0)
          .then(exec(approveJobReqs()));

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.