Skip to content

Instantly share code, notes, and snippets.

@bogdanalbei
bogdanalbei / UserRepository.java
Created March 18, 2018 20:34
Lazy loading repo
public class UserRepository {
public User getById(long id) {
User user = users.get(id);
user.setWallets(() -> walletRepository.getByUserId(id));
return user;
}
}
@bogdanalbei
bogdanalbei / UserWithSupplier.java
Created March 18, 2018 20:30
Lazy loading supplier
public class User {
private long id;
private String name;
private Supplier<List<Wallet>> wallets;
public void setWallets(Supplier<List<Wallet>> wallets) {
this.wallets = wallets;
}
public List<Wallet> getWallets() {
@bogdanalbei
bogdanalbei / User.java
Created March 18, 2018 20:21
Lazy loading
public class User {
private long id;
private String name;
private List<Wallet> wallets;
}
@bogdanalbei
bogdanalbei / ubuntu-Dockerfile
Created September 21, 2017 10:31
Ubuntu Dockerfile
FROM ubuntu
CMD ["tail", "-f", "/dev/null"]
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: ubuntu-test
spec:
replicas: 1
template:
metadata:
labels:
app: ubuntu-test
@Test
public void test_fruit_is_routed_to_the_fruits_processor_via_groceries_queue() throws InterruptedException {
//given
Fruit apple = new Fruit("apple", "England");
ProducerTemplate producer = camelContext.createProducerTemplate();
//when
producer.sendBody(GroceriesRouteBuilder.GROCERIES_QUEUE, apple);
//then
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(
classes = {GroceriesRouteBuilderTest.ContextConfig.class},
loader = CamelSpringDelegatingTestContextLoader.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class GroceriesRouteBuilderTest {
@Autowired
@Qualifier(GroceriesRouteBuilder.FRUIT_PROCESSOR)
MockEndpoint fruitProcessor;
public class GroceriesRouteBuilder extends RouteBuilder {
public static final String VEGETABLES_QUEUE = "seda:vegetables";
public static final String FRUITS_QUEUE = "seda:fruits";
public static final String GROCERIES_QUEUE = "seda:groceries";
public static final String FRUIT_PROCESSOR = "fruitProcessor";
public static final String VEGETABLE_PROCESSOR = "vegetableProcessor";
public void configure() {
from(FRUITS_QUEUE)
.to(FRUIT_PROCESSOR);
@bogdanalbei
bogdanalbei / git-rewrite-to-subfolder
Last active September 26, 2016 14:04
Integrating a submodule into the parent repository fix
#!/bin/bash
# We need the TAB character for SED (Mac OS X sed does not understand \t)
TAB="$(printf '\t')"
function abort {
echo "$(tput setaf 1)$1$(tput sgr0)"
exit 1
}
function request_input {
$ php client.php
Connecting to KrunchyKreme server localhost:9090
Time taken to connect: 0.003
Time taken to fetch menu: 0.003
The KrunchyKreme Menu:
Doughut id=1, name=The Caramel One
Doughut id=2, name=The Chocolate Custard One
Doughut id=3, name=The Cookie One
Doughut id=4, name=The Straberries Jam One
Successful order for 1 X doughnut id 1