This file contains hidden or 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
| public static Stream<TestCase> source() { | |
| return Stream.of( | |
| new TestCase(5, new int[0], false), | |
| new TestCase(5, new int[] {5}, false), | |
| new TestCase(3, new int[] {1, 4, 2}, true), | |
| new TestCase(3, new int[] {1, 2}, true), | |
| new TestCase(3, new int[] {1, 4, 5, 8, 12}, false), | |
| new TestCase(13, new int[] {1, 4, 5, 8, 12}, true), | |
| new TestCase(12, new int[] {1, 4, 5, 8, 12}, true) | |
| ); |
This file contains hidden or 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
| public class Problem1Test { | |
| private static record TestCase(int target, int[] array, boolean expected) { | |
| } | |
| } |
This file contains hidden or 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
| /** | |
| * Given a list of numbers and a number k, return whether any two numbers from the list add up to k. | |
| * <p> | |
| * For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. | |
| * <p> | |
| * Bonus: Can you do this in one pass? | |
| */ | |
| public class Problem { | |
| public boolean check(int target, int[] array) { |
This file contains hidden or 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
| <build> | |
| <pluginManagement> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-compiler-plugin</artifactId> | |
| <version>3.8.1</version> | |
| <configuration> | |
| <source>14</source> | |
| <target>14</target> |
This file contains hidden or 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
| <dependency> | |
| <groupId>org.junit.jupiter</groupId> | |
| <artifactId>junit-jupiter-api</artifactId> | |
| <version>5.6.2</version> | |
| <scope>test</scope> | |
| </dependency> | |
| <dependency> | |
| <groupId>org.junit.jupiter</groupId> | |
| <artifactId>junit-jupiter-params</artifactId> |
This file contains hidden or 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 | |
| public class XaRoute extends RouteBuilder { | |
| @Override | |
| public void configure() { | |
| from("activemq:TestQueue") | |
| .transacted("policyPropagationRequired") | |
| .to("sql:insert into message(contents) values(:#${body})") | |
| .log("Delay...") | |
| .delay(10000) |
This file contains hidden or 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
| @Configuration | |
| public class TransactionConfig { | |
| @Bean("policyPropagationRequired") | |
| public SpringTransactionPolicy transactionPolicyPropagationRequired( | |
| @Autowired JtaTransactionManager transactionManager) { | |
| SpringTransactionPolicy policy = new SpringTransactionPolicy(transactionManager); | |
| policy.setPropagationBehaviorName("PROPAGATION_REQUIRED"); | |
| return policy; | |
| } |
This file contains hidden or 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
| @Configuration | |
| public class ActiveMQConfig { | |
| @Bean("activemq") | |
| public ActiveMQComponent activeMq( | |
| ConnectionFactory connectionFactory, | |
| JtaTransactionManager jtaTransactionManager) { | |
| ActiveMQComponent component = new ActiveMQComponent(); | |
| component.setAcknowledgementMode(JmsProperties.AcknowledgeMode.CLIENT.getMode()); | |
| component.setCacheLevelName("CACHE_CONSUMER"); |
This file contains hidden or 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
| drop table if exists message; | |
| create table message ( | |
| id serial primary key, | |
| contents varchar(256) not null | |
| ); |
This file contains hidden or 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
| spring: | |
| activemq: | |
| # we'll use an external ActiveMQ broker | |
| broker-url: tcp://localhost:61616 | |
| datasource: | |
| # we'll use an external PostgreSQL database | |
| url: jdbc:postgresql://localhost:5432/xatest | |
| xa: | |
| # this is needed to make sure the PostgreSQL data source is XA-aware | |
| data-source-class-name: org.postgresql.xa.PGXADataSource |