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
val list = mutableListOf<ByteArray>() | |
generateSequence(0) { it + 1 }.forEach { | |
if (it % (HEAP_TO_FILL / INCREMENTS_IN_MB) == 0) list.clear() | |
list.add(ByteArray(INCREMENTS_IN_MB * BYTES_TO_MB)) | |
} |
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
class OrderService( | |
inventoryService: InventoryService, | |
paymentService: PaymentService, | |
shipmentService: ShipmentService, | |
emailService: EmailService) { | |
fun processOrder(order: Order): Status { | |
val customerEmail = customerService.getEmailAddress(order.customerId) | |
val checkItemAvailability = { | |
if (order.items.all { inventoryService.isAvailable(it) }) SUBMITTED else ITEMS_UNAVAILABLE |
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
class EmailService(private val customerEmails: MutableMap<Int, String> = mutableMapOf()) { | |
@KafkaListener(topics = [ORDERS, SHIPMENTS, PAYMENTS]) | |
fun onOrder(order: Order) { | |
customerEmails[order.customerId]?.let { emailGateway.notify(it, "order now at status: ${order.status}") } | |
?: throw RuntimeException("Customer email not found") | |
} | |
@KafkaListener(topics = [CUSTOMERS]) | |
fun onCustomer(customer: Customer) { | |
customerEmails[customer.id] = customer.email |
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
class ShipmentService(private val customerAddresses: MutableMap<Int, String> = mutableMapOf()) { | |
@KafkaListener(topics = [PAYMENTS]) | |
fun onOrder(order: Order) { | |
if (order.status !== PAID) return | |
sendShipment(order, customerAddresses[order.customerId] ?: throw RuntimeException("No address for customer ${order.customerId}")) | |
sendMessage(SHIPMENTS, order.withStatus(SHIPPED)) | |
} | |
@KafkaListener(topics = [CUSTOMERS]) |
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
class InventoryService(private val inventory: MutableMap<Int, Sku> = mutableMapOf()) { | |
@KafkaListener(topics = [SHIPMENTS]) | |
fun onOrder(order: Order) { | |
if (order.status !== SHIPPED) return | |
order.items.forEach { | |
inventory.computeIfPresent(it) { _, v -> v.decrementStock().also { sku -> sendMessage(SKUS, sku) } } | |
} | |
} |
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
class OrderService(private val availableSkus:MutableList<Int> = mutableListOf()) { | |
fun submitOrder(order: Order) { | |
sendMessage( | |
ORDERS, | |
order.withStatus(if (availableSkus.containsAll(order.items)) SUBMITTED else ITEMS_UNAVAILABLE) | |
) | |
} | |
@KafkaListener(topics = [SKUS]) | |
fun onSku(sku: Sku) { |
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
class PaymentService( | |
private val customerAccounts: MutableMap<Int, Int> = mutableMapOf(), | |
private val skuPrices: MutableMap<Int, Double> = mutableMapOf() | |
) { | |
@KafkaListener(topics = [ORDERS]) | |
fun onOrder(order: Order) { | |
if (order.status != SUBMITTED) return | |
val total = order.items.sumOf { skuPrices[it] ?: throw RuntimeException("Customer unknown") } | |
val status = paymentGateway.processPayment( |
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
stage('Build foo-service') { | |
when { changeset pattern: "services/foo-service/*" } | |
steps { | |
Build the foo-service here | |
} | |
} |
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
stage('Example Deploy') { | |
when { | |
branch 'production' | |
} | |
steps { | |
echo 'Deploying' | |
} | |
} |
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
node { | |
stage('Build and test') { | |
echo 'Building and testing...' | |
} | |
if (env.BRANCH_NAME == 'master') { | |
['qa', 'prod'].each { environment -> | |
stage("Deploy to $environment") { | |
echo 'I only execute on the master branch' | |
} | |
} |
NewerOlder