- }
-}
-@enduml
\ No newline at end of file
diff --git a/tls/src/main/java/com/iluwatar/tls/App.java b/tls/src/main/java/com/iluwatar/tls/App.java
deleted file mode 100644
index 5932b72b5..000000000
--- a/tls/src/main/java/com/iluwatar/tls/App.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.tls;
-
-import java.util.Calendar;
-import java.util.concurrent.Executors;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * ThreadLocal pattern
- *
- * This App shows how to create an isolated space per each thread. In this example the usage of
- * SimpleDateFormat is made to be thread-safe. This is an example of the ThreadLocal pattern.
- *
- *
By applying the ThreadLocal pattern you can keep track of application instances or locale
- * settings throughout the handling of a request. The ThreadLocal class works like a static
- * variable, with the exception that it is only bound to the current thread! This allows us to use
- * static variables in a thread-safe way.
- *
- *
In Java, thread-local variables are implemented by the ThreadLocal class object. ThreadLocal
- * holds a variable of type T, which is accessible via get/set methods.
- *
- *
SimpleDateFormat is one of the basic Java classes and is not thread-safe. If you do not
- * isolate the instance of SimpleDateFormat per each thread then problems arise.
- *
- *
App converts the String date value 15/12/2015 to the Date format using the Java class
- * SimpleDateFormat. It does this 20 times using 4 threads, each doing it 5 times. With the usage of
- * as ThreadLocal in DateFormatCallable everything runs well. But if you comment out the ThreadLocal
- * variant (marked with "//TLTL") and comment in the non ThreadLocal variant (marked with
- * "//NTLNTL") you can see what will happen without the ThreadLocal. Most likely you will get
- * incorrect date values and / or exceptions.
- *
- *
This example clearly show what will happen when using non thread-safe classes in a thread. In
- * real life this may happen one in of 1.000 or 10.000 conversions and those are really hard to find
- * errors.
- *
- * @author Thomas Bauer, 2017
- */
-@Slf4j
-public class App {
-
- /**
- * Program entry point.
- *
- * @param args command line args
- */
- public static void main(String[] args) {
- var counterDateValues = 0;
- var counterExceptions = 0;
-
- // Create a callable
- var callableDf = new DateFormatCallable("dd/MM/yyyy", "15/12/2015");
- // start 4 threads, each using the same Callable instance
- var executor = Executors.newCachedThreadPool();
-
- var futureResult1 = executor.submit(callableDf);
- var futureResult2 = executor.submit(callableDf);
- var futureResult3 = executor.submit(callableDf);
- var futureResult4 = executor.submit(callableDf);
- try {
- var result = new Result[4];
- result[0] = futureResult1.get();
- result[1] = futureResult2.get();
- result[2] = futureResult3.get();
- result[3] = futureResult4.get();
-
- // Print results of thread executions (converted dates and raised exceptions)
- // and count them
- for (var value : result) {
- counterDateValues = counterDateValues + printAndCountDates(value);
- counterExceptions = counterExceptions + printAndCountExceptions(value);
- }
-
- // a correct run should deliver 20 times 15.12.2015
- // and a correct run shouldn't deliver any exception
- LOGGER.info("The List dateList contains " + counterDateValues + " date values");
- LOGGER.info("The List exceptionList contains " + counterExceptions + " exceptions");
-
- } catch (Exception e) {
- LOGGER.info("Abnormal end of program. Program throws exception: " + e);
- }
- executor.shutdown();
- }
-
- /**
- * Print result (date values) of a thread execution and count dates.
- *
- * @param res contains results of a thread execution
- */
- private static int printAndCountDates(Result res) {
- // a correct run should deliver 5 times 15.12.2015 per each thread
- var counter = 0;
- for (var dt : res.getDateList()) {
- counter++;
- var cal = Calendar.getInstance();
- cal.setTime(dt);
- // Formatted output of the date value: DD.MM.YYYY
- LOGGER.info(cal.get(Calendar.DAY_OF_MONTH) + "."
- + cal.get(Calendar.MONTH) + "."
- + cal.get(Calendar.YEAR)
- );
- }
- return counter;
- }
-
- /**
- * Print result (exceptions) of a thread execution and count exceptions.
- *
- * @param res contains results of a thread execution
- * @return number of dates
- */
- private static int printAndCountExceptions(Result res) {
- // a correct run shouldn't deliver any exception
- var counter = 0;
- for (var ex : res.getExceptionList()) {
- counter++;
- LOGGER.info(ex);
- }
- return counter;
- }
-}
diff --git a/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java b/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java
deleted file mode 100644
index e6d7ef9b4..000000000
--- a/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.tls;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.concurrent.Callable;
-import java.util.stream.IntStream;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * DateFormatCallable converts string dates to a date format using SimpleDateFormat. The date format
- * and the date value will be passed to the Callable by the constructor. The constructor creates a
- * instance of SimpleDateFormat and stores it in a ThreadLocal class variable. For the complete
- * description of the example see {@link App}.
- *
- *
You can comment out the code marked with //TLTL and comment in the code marked //NTLNTL. Then
- * you can see what will happen if you do not use the ThreadLocal. For details see the description
- * of {@link App}
- *
- * @author Thomas Bauer, 2017
- */
-@Slf4j
-public class DateFormatCallable implements Callable {
-
- // class variables (members)
- private final ThreadLocal df; //TLTL
- // private DateFormat df; //NTLNTL
-
- private final String dateValue; // for dateValue Thread Local not needed
-
-
- /**
- * The date format and the date value are passed to the constructor.
- *
- * @param inDateFormat string date format string, e.g. "dd/MM/yyyy"
- * @param inDateValue string date value, e.g. "21/06/2016"
- */
- public DateFormatCallable(String inDateFormat, String inDateValue) {
- final var idf = inDateFormat; //TLTL
- this.df = ThreadLocal.withInitial(() -> { //TLTL
- return new SimpleDateFormat(idf); //TLTL
- }); //TLTL
- // this.df = new SimpleDateFormat(inDateFormat); //NTLNTL
- this.dateValue = inDateValue;
- }
-
- @Override
- public Result call() {
- LOGGER.info(Thread.currentThread() + " started executing...");
- var result = new Result();
-
- // Convert date value to date 5 times
- IntStream.rangeClosed(1, 5).forEach(i -> {
- try {
- // this is the statement where it is important to have the
- // instance of SimpleDateFormat locally
- // Create the date value and store it in dateList
- result.getDateList().add(this.df.get().parse(this.dateValue)); //TLTL
- // result.getDateList().add(this.df.parse(this.dateValue)); //NTLNTL
- } catch (Exception e) {
- // write the Exception to a list and continue work
- result.getExceptionList().add(e.getClass() + ": " + e.getMessage());
- }
- });
-
- LOGGER.info("{} finished processing part of the thread", Thread.currentThread());
-
- return result;
- }
-}
diff --git a/tls/src/main/java/com/iluwatar/tls/Result.java b/tls/src/main/java/com/iluwatar/tls/Result.java
deleted file mode 100644
index 48e30a525..000000000
--- a/tls/src/main/java/com/iluwatar/tls/Result.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-/*
- * Fiducia IT AG, All rights reserved. Use is subject to license terms.
- */
-
-package com.iluwatar.tls;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-/**
- * Result object that will be returned by the Callable {@link DateFormatCallable} used in {@link
- * App}.
- *
- * @author Thomas Bauer, 2017
- */
-public class Result {
- // A list to collect the date values created in one thread
- private final List dateList = new ArrayList<>();
-
- // A list to collect Exceptions thrown in one threads (should be none in
- // this example)
- private final List exceptionList = new ArrayList<>();
-
- /**
- * Get list of date values collected within a thread execution.
- *
- * @return List of date values collected within an thread execution
- */
- public List getDateList() {
- return dateList;
- }
-
- /**
- * Get list of exceptions thrown within a thread execution.
- *
- * @return List of exceptions thrown within an thread execution
- */
- public List getExceptionList() {
- return exceptionList;
- }
-}
diff --git a/tls/src/test/java/com/iluwatar/tls/AppTest.java b/tls/src/test/java/com/iluwatar/tls/AppTest.java
deleted file mode 100644
index fa53ee34d..000000000
--- a/tls/src/test/java/com/iluwatar/tls/AppTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.tls;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-
-/**
- * Tests that thread local storage example runs without errors.
- *
- * @author Thomas Bauer, January 2017
- */
-class AppTest {
- @Test
- void shouldExecuteApplicationWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
- }
-}
diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java
deleted file mode 100644
index 3bd9497be..000000000
--- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.tls;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.concurrent.Executors;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test of the Callable
- *
- * In this test {@link DateFormatCallable} is tested with only one thread (i.e. without concurrency
- * situation)
- *
- * After a successful run 5 date values should be in the result object. All dates should have the
- * same value (15.11.2015). To avoid problems with time zone not the date instances themselves are
- * compared by the test. For the test the dates are converted into string format DD.MM.YYY
- *
- * Additionally the number of list entries are tested for both the list with the date values and the
- * list with the exceptions
- *
- * @author Thomas Bauer, January 2017
- */
-class DateFormatCallableTest {
-
- // Class variables used in setup() have to be static because setup() has to be static
- /**
- * Result object given back by DateFormatCallable -- Array with converted date values -- Array
- * with thrown exceptions
- */
- private static Result result;
-
- /**
- * The date values created by the run of of DateFormatRunnalbe. List will be filled in the setup()
- * method
- */
- private static List createdDateValues = new ArrayList<>();
-
- /**
- * Expected number of date values in the date value list created by the run of DateFormatRunnalbe
- */
- private final int expectedCounterDateValues = 5;
-
- /**
- * Expected number of exceptions in the exception list created by the run of DateFormatRunnalbe.
- */
- private final int expectedCounterExceptions = 0;
-
- /**
- * Expected content of the list containing the date values created by the run of
- * DateFormatRunnalbe
- */
- private final List expectedDateValues =
- List.of("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015");
-
- /**
- * Run Callable and prepare results for usage in the test methods
- */
- @BeforeAll
- public static void setup() {
- // Create a callable
- var callableDf = new DateFormatCallable("dd/MM/yyyy", "15/12/2015");
- // start thread using the Callable instance
- var executor = Executors.newCachedThreadPool();
- var futureResult = executor.submit(callableDf);
- try {
- result = futureResult.get();
- createdDateValues = convertDatesToString(result);
- } catch (Exception e) {
- fail("Setup failed: " + e);
- }
- executor.shutdown();
- }
-
- private static List convertDatesToString(Result res) {
- // Format date value as DD.MM.YYYY
- if (res == null || res.getDateList() == null || res.getDateList().size() == 0) {
- return null;
- }
- var returnList = new ArrayList();
-
- for (var dt : res.getDateList()) {
- var cal = Calendar.getInstance();
- cal.setTime(dt);
- returnList.add(cal.get(Calendar.DAY_OF_MONTH) + "."
- + cal.get(Calendar.MONTH) + "."
- + cal.get(Calendar.YEAR)
- );
- }
- return returnList;
- }
-
- /**
- * Test date values after the run of DateFormatRunnalbe. A correct run should deliver 5 times
- * 15.12.2015
- */
- @Test
- void testDateValues() {
- assertEquals(expectedDateValues, createdDateValues);
- }
-
- /**
- * Test number of dates in the list after the run of DateFormatRunnalbe. A correct run should
- * deliver 5 date values
- */
- @Test
- void testCounterDateValues() {
- assertEquals(expectedCounterDateValues, result.getDateList().size());
- }
-
- /**
- * Test number of Exceptions in the list after the run of DateFormatRunnalbe. A correct run should
- * deliver no exceptions
- */
- @Test
- void testCounterExceptions() {
- assertEquals(expectedCounterExceptions, result.getExceptionList().size());
- }
-}
diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java
deleted file mode 100644
index 69489d4d0..000000000
--- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestIncorrectDateFormat.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.tls;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.util.List;
-import java.util.concurrent.Executors;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test of the Callable
- *
- * In this test {@link DateFormatCallable} is tested with only one thread (i.e. without concurrency
- * situation)
- *
- * An incorrect formatted date is passed to the Callable After a successful run 0 date values and 5
- * exceptions should be in the result object.
- *
- * @author Thomas Bauer, January 2017
- */
-public class DateFormatCallableTestIncorrectDateFormat {
-
- // Class variables used in setup() have to be static because setup() has to be static
- /**
- * Result object given back by DateFormatCallable -- Array with converted date values -- Array
- * with thrown exceptions
- */
- private static Result result;
-
- /**
- * Expected number of date values in the date value list created by the run of DateFormatRunnalbe
- */
- private final int expectedCounterDateValues = 0;
-
- /**
- * Expected number of exceptions in the exception list created by the run of DateFormatRunnalbe.
- */
- private final int expectedCounterExceptions = 5;
-
- /**
- * Expected content of the list containing the exceptions created by the run of
- * DateFormatRunnalbe
- */
- private final List expectedExceptions = List.of(
- "class java.text.ParseException: Unparseable date: \"15.12.2015\"",
- "class java.text.ParseException: Unparseable date: \"15.12.2015\"",
- "class java.text.ParseException: Unparseable date: \"15.12.2015\"",
- "class java.text.ParseException: Unparseable date: \"15.12.2015\"",
- "class java.text.ParseException: Unparseable date: \"15.12.2015\""
- );
-
- /**
- * Run Callable and prepare results for usage in the test methods
- */
- @BeforeAll
- public static void setup() {
- // Create a callable. Pass a string date value not matching the format string
- var callableDf = new DateFormatCallable("dd/MM/yyyy", "15.12.2015");
- // start thread using the Callable instance
- var executor = Executors.newCachedThreadPool();
- var futureResult = executor.submit(callableDf);
- try {
- result = futureResult.get();
- } catch (Exception e) {
- fail("Setup failed: " + e);
- }
- executor.shutdown();
- }
-
- /**
- * Test Exceptions after the run of DateFormatRunnalbe. A correct run should deliver 5 times the
- * same exception
- */
- @Test
- void testExceptions() {
- assertEquals(expectedExceptions, result.getExceptionList());
- }
-
- /**
- * Test number of dates in the list after the run of DateFormatRunnalbe. A correct run should
- * deliver no date values
- */
- @Test
- void testCounterDateValues() {
- assertEquals(expectedCounterDateValues, result.getDateList().size());
- }
-
- /**
- * Test number of Exceptions in the list after the run of DateFormatRunnalbe. A correct run should
- * deliver 5 exceptions
- */
- @Test
- void testCounterExceptions() {
- assertEquals(expectedCounterExceptions, result.getExceptionList().size());
- }
-}
diff --git a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java b/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java
deleted file mode 100644
index f8b7f952a..000000000
--- a/tls/src/test/java/com/iluwatar/tls/DateFormatCallableTestMultiThread.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.tls;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.concurrent.Executors;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test of the Callable
- *
- * In this test {@link DateFormatCallable} is used by 4 threads in parallel
- *
- * After a successful run 5 date values should be in the result object of each thread. All dates
- * should have the same value (15.11.2015). To avoid problems with time zone not the date instances
- * themselves are compared by the test. For the test the dates are converted into string format
- * DD.MM.YYY
- *
- * Additionally the number of list entries are tested for both the list with the date values and the
- * list with the exceptions
- *
- * @author Thomas Bauer, January 2017
- */
-public class DateFormatCallableTestMultiThread {
-
- // Class variables used in setup() have to be static because setup() has to be static
- /**
- * Result object given back by DateFormatCallable, one for each thread -- Array with converted
- * date values -- Array with thrown exceptions
- */
- private static final Result[] result = new Result[4];
-
- /**
- * The date values created by the run of of DateFormatRunnalbe. List will be filled in the setup()
- * method
- */
- @SuppressWarnings("serial")
- private static class StringArrayList extends ArrayList {
- /* nothing needed here */
- }
-
- private static final List[] createdDateValues = new StringArrayList[4];
-
- /**
- * Expected number of date values in the date value list created by each thread
- */
- private final int expectedCounterDateValues = 5;
-
- /**
- * Expected number of exceptions in the exception list created by each thread
- */
- private final int expectedCounterExceptions = 0;
-
- /**
- * Expected content of the list containing the date values created by each thread
- */
- private final List expectedDateValues =
- List.of("15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015", "15.11.2015");
-
- /**
- * Run Callable and prepare results for usage in the test methods
- */
- @BeforeAll
- public static void setup() {
- // Create a callable
- var callableDf = new DateFormatCallable("dd/MM/yyyy", "15/12/2015");
- // start thread using the Callable instance
- var executor = Executors.newCachedThreadPool();
- var futureResult1 = executor.submit(callableDf);
- var futureResult2 = executor.submit(callableDf);
- var futureResult3 = executor.submit(callableDf);
- var futureResult4 = executor.submit(callableDf);
- try {
- result[0] = futureResult1.get();
- result[1] = futureResult2.get();
- result[2] = futureResult3.get();
- result[3] = futureResult4.get();
- for (var i = 0; i < result.length; i++) {
- createdDateValues[i] = convertDatesToString(result[i]);
- }
- } catch (Exception e) {
- fail("Setup failed: " + e);
- }
- executor.shutdown();
- }
-
- private static List convertDatesToString(Result res) {
- // Format date value as DD.MM.YYYY
- if (res == null || res.getDateList() == null || res.getDateList().size() == 0) {
- return null;
- }
- var returnList = new StringArrayList();
-
- for (var dt : res.getDateList()) {
- var cal = Calendar.getInstance();
- cal.setTime(dt);
- returnList.add(cal.get(Calendar.DAY_OF_MONTH) + "."
- + cal.get(Calendar.MONTH) + "."
- + cal.get(Calendar.YEAR)
- );
- }
- return returnList;
- }
-
- /**
- * Test date values after the run of DateFormatRunnalbe. A correct run should deliver 5 times
- * 15.12.2015 by each thread
- */
- @Test
- void testDateValues() {
- for (var createdDateValue : createdDateValues) {
- assertEquals(expectedDateValues, createdDateValue);
- }
- }
-
- /**
- * Test number of dates in the list after the run of DateFormatRunnalbe. A correct run should
- * deliver 5 date values by each thread
- */
- @Test
- void testCounterDateValues() {
- for (var value : result) {
- assertEquals(expectedCounterDateValues, value.getDateList().size());
- }
- }
-
- /**
- * Test number of Exceptions in the list after the run of DateFormatRunnalbe. A correct run should
- * deliver no exceptions
- */
- @Test
- void testCounterExceptions() {
- for (var value : result) {
- assertEquals(expectedCounterExceptions, value.getExceptionList().size());
- }
- }
-}