This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.codehaus.gpars', module='gpars', version='1.2.1') | |
import static groovyx.gpars.GParsPool.withPool | |
withPool(100) { | |
(1..2000).eachParallel { i -> | |
def beginTime = System.currentTimeMillis() | |
def result = 'https://xxxxx.execute-api.us-east-1.amazonaws.com/dev/users'.toURL().text | |
println "${i}: ${System.currentTimeMillis() - beginTime}" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Builder | |
@ToString(includePackage = false) | |
@CompileStatic | |
class Response { | |
int statusCode | |
String body | |
private Map<String, String> headers = [:] | |
void addHeader(String key, String value) { | |
headers.put(key, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.amazonaws.services.lambda.runtime.Context | |
import groovy.transform.ToString | |
@ToString(includePackage = false) | |
class Request { | |
private final Map input | |
private final Context context | |
Request(final Map input, final Context context) { | |
this.input = input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Log4j | |
@CompileStatic | |
class GetUsers implements Handler { | |
@Autowired | |
private UserRepository userRepository | |
@Override | |
boolean route(final Request request) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Log4j | |
@CompileStatic | |
class FindUsersByLastName implements Handler { | |
@Autowired | |
private UserRepository userRepository | |
@Override | |
boolean route(final Request request) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Log4j | |
@CompileStatic | |
class CreateUser implements Handler { | |
@Autowired | |
private UserRepository userRepository | |
@Override | |
boolean route(Request request) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Handler { | |
boolean route(Request request) | |
Response respond(Request request) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.serverless.persistence.entities.User | |
import org.springframework.data.repository.CrudRepository | |
interface UserRepository extends CrudRepository<User, Long> { | |
List<User> findByLastName(String lastName) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@ToString | |
@CompileStatic | |
class User { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
Long id | |
String firstName | |
String lastName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@CompileStatic | |
@Log4j | |
class DispatcherService { | |
@Autowired | |
List<Handler> handlers | |
Response dispatch(Request request) { | |
log.info("request: ${request}") |