diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java similarity index 72% rename from core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java rename to core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java index 7e2bf590fd..cd8b015be2 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishManualTest.java @@ -10,9 +10,9 @@ import java.util.concurrent.*; import static junit.framework.TestCase.assertTrue; -public class WaitingForThreadsToFinishTest { +public class WaitingForThreadsToFinishManualTest { - private static final Logger LOG = LoggerFactory.getLogger(WaitingForThreadsToFinishTest.class); + private static final Logger LOG = LoggerFactory.getLogger(WaitingForThreadsToFinishManualTest.class); private final static ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10); public void awaitTerminationAfterShutdown(ExecutorService threadPool) { @@ -142,66 +142,4 @@ public class WaitingForThreadsToFinishTest { awaitTerminationAfterShutdown(WORKER_THREAD_POOL); } } - - @Test - public void givenMultipleThreads_whenUsingCompletableFutures_thenMainThreadShouldWaitForAllToFinish() { - - CompletableFuture future1 = CompletableFuture.supplyAsync(() -> { - - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return "Hello"; - }); - - CompletableFuture future2 = CompletableFuture.supplyAsync(() -> { - - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return "Beautiful"; - }); - - CompletableFuture future3 = CompletableFuture.supplyAsync(() -> { - - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return "World"; - }); - - long startProcessingTime = System.currentTimeMillis(); - CompletableFuture combinedFuture = CompletableFuture.allOf(future1, future2, future3); - combinedFuture.join(); - - long totalProcessingTime = System.currentTimeMillis() - startProcessingTime; - assertTrue(totalProcessingTime >= 5000 && totalProcessingTime < 6000); - - LOG.debug("Responses from all threads are available after " + totalProcessingTime + " milliseconds"); - - try { - String thread1Response = future1.get(); - assertTrue(thread1Response.equals("Hello")); - - String thread2Response = future2.get(); - assertTrue(thread2Response.equals("Beautiful")); - - String thread3Response = future3.get(); - assertTrue(thread3Response.equals("World")); - - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - - awaitTerminationAfterShutdown(WORKER_THREAD_POOL); - } } diff --git a/flyway/pom.xml b/flyway/pom.xml deleted file mode 100644 index 5cb8fabe67..0000000000 --- a/flyway/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - 4.0.0 - flyway - 1.0 - flyway - pom - A sample project to demonstrate Flyway migrations - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - spring-flyway - - - - - mysql - mysql-connector-java - ${mysql.version} - - - - - - org.springframework.boot - spring-boot-dependencies - ${spring.boot.version} - pom - import - - - - - - - org.flywaydb - flyway-maven-plugin - ${flyway-maven-plugin.version} - - - - - 6.0.5 - 4.0.3 - 1.5.8.RELEASE - - \ No newline at end of file diff --git a/flyway/spring-flyway/.gitignore b/flyway/spring-flyway/.gitignore deleted file mode 100644 index 2af7cefb0a..0000000000 --- a/flyway/spring-flyway/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ \ No newline at end of file diff --git a/flyway/spring-flyway/pom.xml b/flyway/spring-flyway/pom.xml deleted file mode 100644 index cf5703cfab..0000000000 --- a/flyway/spring-flyway/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - 4.0.0 - - spring-flyway - 0.0.1-SNAPSHOT - jar - - spring-flyway - Spring Boot Test Flyway Migrations - - - flyway - com.baeldung - 1.0 - ../../flyway - - - - UTF-8 - UTF-8 - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.flywaydb - flyway-core - - - org.projectlombok - lombok - - - com.h2database - h2 - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/SpringFlywayApplication.java b/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/SpringFlywayApplication.java deleted file mode 100644 index 9218fbc88d..0000000000 --- a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/SpringFlywayApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.springflyway; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringFlywayApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringFlywayApplication.class, args); - } -} diff --git a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/entities/Customer.java b/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/entities/Customer.java deleted file mode 100644 index 194b961d2d..0000000000 --- a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/entities/Customer.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.springflyway.entities; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -@Data -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class Customer { - - @Id - @GeneratedValue - private Long id; - - private String firstName; - private String lastName; - - private String email; - -} diff --git a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/migration/V2__uk_lastname_customer.java b/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/migration/V2__uk_lastname_customer.java deleted file mode 100644 index 52b851546b..0000000000 --- a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/migration/V2__uk_lastname_customer.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.springflyway.migration; - -import org.flywaydb.core.api.migration.spring.SpringJdbcMigration; -import org.springframework.jdbc.core.JdbcTemplate; - -public class V2__uk_lastname_customer implements SpringJdbcMigration { - - final String CUSTOMER_LASTNAME_UK = "ALTER TABLE customer ADD CONSTRAINT uk_customer_lastname UNIQUE(last_name);"; - - @Override - public void migrate(final JdbcTemplate jdbcTemplate) throws Exception { - jdbcTemplate.execute(CUSTOMER_LASTNAME_UK); - } -} diff --git a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/repositories/CustomerRepository.java b/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/repositories/CustomerRepository.java deleted file mode 100644 index 0a1fb5a146..0000000000 --- a/flyway/spring-flyway/src/main/java/com/baeldung/springflyway/repositories/CustomerRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.springflyway.repositories; - -import com.baeldung.springflyway.entities.Customer; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface CustomerRepository extends JpaRepository { - - Optional findByEmail(String email); -} diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationIntegrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationIntegrationTest.java deleted file mode 100644 index 59ef5820d7..0000000000 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInitialMigrationIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.springflyway; - -import com.baeldung.springflyway.entities.Customer; -import com.baeldung.springflyway.repositories.CustomerRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.junit.Assert.assertNotNull; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class CustomerRepositoryInitialMigrationIntegrationTest { - - @Autowired CustomerRepository customerRepository; - - @Test - public void givenSchemaCreationMigration_whenTryingToCreateACustomer_thenSuccess() { - Customer customer = customerRepository.save(Customer - .builder() - .email("customer@email.com") - .build()); - assertNotNull(customer.getId()); - } - -} diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataIntegrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataIntegrationTest.java deleted file mode 100644 index 3feedf2fd9..0000000000 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryInsertDataIntegrationTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.springflyway; - -import com.baeldung.springflyway.entities.Customer; -import com.baeldung.springflyway.repositories.CustomerRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.List; -import java.util.Optional; - -import static org.junit.Assert.*; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class CustomerRepositoryInsertDataIntegrationTest { - - @Autowired CustomerRepository customerRepository; - - @Test - public void givenASetInsertData_whenRunningMigrationsWithSuccess_thenASpecificCustomerIsFound() { - Optional customerOptional = customerRepository.findByEmail("email@email.com"); - assertTrue(customerOptional.isPresent()); - } - - @Test - public void givenASetInsertData_whenRunningMigrationsWithSuccess_thenASetOfCustomersIsFound() { - List customers = customerRepository.findAll(); - assertNotNull(customers); - assertEquals(customers.size(), 6); - } - -} diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java deleted file mode 100644 index 9ec5d4d77e..0000000000 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryNotNullConstraintMigrationIntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.springflyway; - -import com.baeldung.springflyway.entities.Customer; -import com.baeldung.springflyway.repositories.CustomerRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class CustomerRepositoryNotNullConstraintMigrationIntegrationTest { - - @Autowired CustomerRepository customerRepository; - - @Test(expected = DataIntegrityViolationException.class) - public void givenTheNotNullConstraintMigrations_whenInsertingACustomerWithNullEmail_thenThrowException() { - customerRepository.save(Customer - .builder() - .build()); - } - -} diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java deleted file mode 100644 index f615f477bc..0000000000 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.springflyway; - -import com.baeldung.springflyway.entities.Customer; -import com.baeldung.springflyway.repositories.CustomerRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(properties = { - "flyway.locations[0]=db/migration", "flyway.locations[1]=com/baeldung/springflyway/migration" -}) -public class CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest { - - @Autowired CustomerRepository customerRepository; - - @Test(expected = DataIntegrityViolationException.class) - public void givenTheUniqueConstraintMigrations_whenInsertingAnExistingLastNameCustomer_thenThrowException() { - customerRepository.save(Customer - .builder() - .lastName("LastName") - .build()); - - } - -} diff --git a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java b/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java deleted file mode 100644 index e9ac34b384..0000000000 --- a/flyway/spring-flyway/src/test/java/com/baeldung/springflyway/CustomerRepositoryUniqueConstraintMigrationIntegrationTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.springflyway; - -import com.baeldung.springflyway.entities.Customer; -import com.baeldung.springflyway.repositories.CustomerRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class CustomerRepositoryUniqueConstraintMigrationIntegrationTest { - - @Autowired CustomerRepository customerRepository; - - @Test(expected = DataIntegrityViolationException.class) - public void givenTheUniqueConstraintMigrations_whenInsertingAnExistingEmailCustomer_thenThrowException() { - customerRepository.save(Customer - .builder() - .email("email@email.com") - .build()); - - } - -} diff --git a/flyway/spring-flyway/src/test/resources/application.properties b/flyway/spring-flyway/src/test/resources/application.properties deleted file mode 100644 index 5656ca79ce..0000000000 --- a/flyway/spring-flyway/src/test/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.jpa.hibernate.ddl-auto=validate \ No newline at end of file diff --git a/flyway/spring-flyway/src/test/resources/db/migration/V1_0__create_table_customer.sql b/flyway/spring-flyway/src/test/resources/db/migration/V1_0__create_table_customer.sql deleted file mode 100644 index 8c65253ed8..0000000000 --- a/flyway/spring-flyway/src/test/resources/db/migration/V1_0__create_table_customer.sql +++ /dev/null @@ -1,6 +0,0 @@ -create table if not exists customer ( - id bigint AUTO_INCREMENT not null primary key, - first_name varchar(255) , - last_name varchar(255) , - email varchar(255) -); \ No newline at end of file diff --git a/flyway/spring-flyway/src/test/resources/db/migration/V1_1__insert_customer.sql b/flyway/spring-flyway/src/test/resources/db/migration/V1_1__insert_customer.sql deleted file mode 100644 index 6bba6e00a1..0000000000 --- a/flyway/spring-flyway/src/test/resources/db/migration/V1_1__insert_customer.sql +++ /dev/null @@ -1,6 +0,0 @@ -insert into customer (first_name, last_name, email) values ('FirstName', 'LastName', 'email@email.com'); -insert into customer (first_name, last_name, email) values ('FirstName1', 'LastName1', 'email1@email.com'); -insert into customer (first_name, last_name, email) values ('FirstName2', 'LastName2', 'email2@email.com'); -insert into customer (first_name, last_name, email) values ('FirstName3', 'LastName3', 'email3@email.com'); -insert into customer (first_name, last_name, email) values ('FirstName4', 'LastName4', 'email4@email.com'); -insert into customer (first_name, last_name, email) values ('FirstName5', 'LastName5', 'email5@email.com'); \ No newline at end of file diff --git a/flyway/spring-flyway/src/test/resources/db/migration/V1_2__make_email_not_null.sql b/flyway/spring-flyway/src/test/resources/db/migration/V1_2__make_email_not_null.sql deleted file mode 100644 index b1cc396741..0000000000 --- a/flyway/spring-flyway/src/test/resources/db/migration/V1_2__make_email_not_null.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE customer ALTER email SET NOT NULL; \ No newline at end of file diff --git a/flyway/spring-flyway/src/test/resources/db/migration/V1_3__make_email_unique.sql b/flyway/spring-flyway/src/test/resources/db/migration/V1_3__make_email_unique.sql deleted file mode 100644 index 19d738fe46..0000000000 --- a/flyway/spring-flyway/src/test/resources/db/migration/V1_3__make_email_unique.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE customer ADD CONSTRAINT uk_customer_email UNIQUE(email); \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2c611e6efe..fa5eb83b0c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,6 @@ feign - flyway