diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-28 15:10:47 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-28 15:10:47 +0200 |
commit | 9bf664ba9a153a404f03c39d5ba0f99eb32c4419 (patch) | |
tree | 1eeda1293a2d453c9acd11deb736be4e53e58975 /container-core/src/test/java/com/yahoo/processing | |
parent | 147fa8c912c8748a9b4eb25c67420841363f3be0 (diff) |
Convert container-core to junit5
Diffstat (limited to 'container-core/src/test/java/com/yahoo/processing')
14 files changed, 546 insertions, 561 deletions
diff --git a/container-core/src/test/java/com/yahoo/processing/ResponseTestCase.java b/container-core/src/test/java/com/yahoo/processing/ResponseTestCase.java index f8cd646909d..274bd2050f2 100644 --- a/container-core/src/test/java/com/yahoo/processing/ResponseTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/ResponseTestCase.java @@ -5,11 +5,11 @@ import com.yahoo.processing.response.ArrayDataList; import com.yahoo.processing.response.DataList; import com.yahoo.processing.test.ProcessorLibrary; import com.yahoo.processing.test.Responses; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.ExecutionException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author bratseth @@ -24,7 +24,7 @@ public class ResponseTestCase { */ @SuppressWarnings({"unchecked"}) @Test - public void testRecursiveCompletionAndToString() throws InterruptedException, ExecutionException { + void testRecursiveCompletionAndToString() throws InterruptedException, ExecutionException { // create lists Request request = new Request(); DataList list1 = ArrayDataList.create(request); @@ -48,22 +48,22 @@ public class ResponseTestCase { list123.add(list1231); list123.add(list1232); // add sync data elements - list1.add(new ProcessorLibrary.StringData(request,"list1")); - list12.add(new ProcessorLibrary.StringData(request,"list12")); - list14.add(new ProcessorLibrary.StringData(request,"list14")); - list122.add(new ProcessorLibrary.StringData(request,"list122")); - list1231.add(new ProcessorLibrary.StringData(request,"list1231")); + list1.add(new ProcessorLibrary.StringData(request, "list1")); + list12.add(new ProcessorLibrary.StringData(request, "list12")); + list14.add(new ProcessorLibrary.StringData(request, "list14")); + list122.add(new ProcessorLibrary.StringData(request, "list122")); + list1231.add(new ProcessorLibrary.StringData(request, "list1231")); - assertEqualsIgnoreObjectNumbers("Uncompleted tree, no incoming",uncompletedTreeUncompletedIncoming,Responses.recursiveToString(list1)); + assertEqualsIgnoreObjectNumbers("Uncompleted tree, no incoming", uncompletedTreeUncompletedIncoming, Responses.recursiveToString(list1)); // provide all async incoming data list12.incoming().markComplete(); - list121.incoming().addLast(new ProcessorLibrary.StringData(request,"list121async1")); + list121.incoming().addLast(new ProcessorLibrary.StringData(request, "list121async1")); list123.incoming().markComplete(); - list1231.incoming().add(new ProcessorLibrary.StringData(request,"list13231async1")); - list1231.incoming().addLast(new ProcessorLibrary.StringData(request,"list1231async2")); - list13.incoming().add(new ProcessorLibrary.StringData(request,"list13async1")); - list13.incoming().addLast(new ProcessorLibrary.StringData(request,"list13async2")); + list1231.incoming().add(new ProcessorLibrary.StringData(request, "list13231async1")); + list1231.incoming().addLast(new ProcessorLibrary.StringData(request, "list1231async2")); + list13.incoming().add(new ProcessorLibrary.StringData(request, "list13async1")); + list13.incoming().addLast(new ProcessorLibrary.StringData(request, "list13async2")); assertEqualsIgnoreObjectNumbers("Uncompleted tree, incoming complete", uncompletedTreeCompletedIncoming, Responses.recursiveToString(list1)); @@ -73,7 +73,7 @@ public class ResponseTestCase { } private void assertEqualsIgnoreObjectNumbers(String explanation,String expected,String actual) { - assertEquals(explanation,expected,removeObjectNumbers(actual)); + assertEquals(expected,removeObjectNumbers(actual),explanation); } /** Removes all object numbers (occurrences of @hexnumber) */ diff --git a/container-core/src/test/java/com/yahoo/processing/execution/test/AsyncExecutionTestCase.java b/container-core/src/test/java/com/yahoo/processing/execution/test/AsyncExecutionTestCase.java index 22f69a87bc3..fb469c36e14 100644 --- a/container-core/src/test/java/com/yahoo/processing/execution/test/AsyncExecutionTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/execution/test/AsyncExecutionTestCase.java @@ -6,10 +6,10 @@ import com.yahoo.processing.Processor; import com.yahoo.processing.Request; import com.yahoo.processing.Response; import com.yahoo.processing.execution.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.processing.test.ProcessorLibrary.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author bratseth @@ -18,29 +18,29 @@ public class AsyncExecutionTestCase { /** Execute a processing chain which forks off into multiple threads */ @Test - public void testAsyncExecution() { + void testAsyncExecution() { // Create a chain - Chain<Processor> chain=new Chain<>(new CombineData(),new BlockingSplitter(2),new Get6DataItems(), new DataSource()); + Chain<Processor> chain = new Chain<>(new CombineData(), new BlockingSplitter(2), new Get6DataItems(), new DataSource()); // Execute it - Request request=new Request(); - request.properties().set("appendage",1); - Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + request.properties().set("appendage", 1); + Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); // Verify the result - assertEquals(6*2-1,response.data().asList().size()); - assertEquals("first.2, third.2",response.data().get(0).toString()); - assertEquals("second.2",response.data().get(1).toString()); - assertEquals("first.3",response.data().get(2).toString()); - assertEquals("second.3",response.data().get(3).toString()); - assertEquals("third.3",response.data().get(4).toString()); + assertEquals(6 * 2 - 1, response.data().asList().size()); + assertEquals("first.2, third.2", response.data().get(0).toString()); + assertEquals("second.2", response.data().get(1).toString()); + assertEquals("first.3", response.data().get(2).toString()); + assertEquals("second.3", response.data().get(3).toString()); + assertEquals("third.3", response.data().get(4).toString()); // from the parallel execution - assertEquals("first.2",response.data().get(5).toString()); - assertEquals("second.2",response.data().get(6).toString()); - assertEquals("third.2",response.data().get(7).toString()); - assertEquals("first.3",response.data().get(8).toString()); - assertEquals("second.3",response.data().get(9).toString()); - assertEquals("third.3",response.data().get(10).toString()); + assertEquals("first.2", response.data().get(5).toString()); + assertEquals("second.2", response.data().get(6).toString()); + assertEquals("third.2", response.data().get(7).toString()); + assertEquals("first.3", response.data().get(8).toString()); + assertEquals("second.3", response.data().get(9).toString()); + assertEquals("third.3", response.data().get(10).toString()); } } diff --git a/container-core/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java b/container-core/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java index c8c489b2f9d..ce7a747d676 100644 --- a/container-core/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/execution/test/ExecutionContextTestCase.java @@ -5,16 +5,13 @@ import com.yahoo.component.chain.Chain; import com.yahoo.processing.Processor; import com.yahoo.processing.execution.Execution; import com.yahoo.processing.test.ProcessorLibrary; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -25,53 +22,53 @@ public class ExecutionContextTestCase { /** Tests combined use of trace messages, context values and access log entries */ @Test - public void testtrace() { - Execution execution1=Execution.createRoot(chain,2,Execution.Environment.createEmpty()); - execution1.trace().setProperty("a","a1"); - execution1.trace().logValue("a","a1"); + void testtrace() { + Execution execution1 = Execution.createRoot(chain, 2, Execution.Environment.createEmpty()); + execution1.trace().setProperty("a", "a1"); + execution1.trace().logValue("a", "a1"); execution1.trace().trace("root 1", 2); - execution1.trace().setProperty("a","a2"); - execution1.trace().setProperty("b","b1"); - execution1.trace().logValue("a","a2"); - execution1.trace().logValue("b","b1"); - - Execution execution2=new Execution(chain,execution1); - execution2.trace().setProperty("b","b2"); - execution2.trace().logValue("b","b2"); + execution1.trace().setProperty("a", "a2"); + execution1.trace().setProperty("b", "b1"); + execution1.trace().logValue("a", "a2"); + execution1.trace().logValue("b", "b1"); + + Execution execution2 = new Execution(chain, execution1); + execution2.trace().setProperty("b", "b2"); + execution2.trace().logValue("b", "b2"); execution2.trace().trace(" child-1 1", 2); execution2.trace().setProperty("b", "b3"); - execution2.trace().logValue("b","b3"); + execution2.trace().logValue("b", "b3"); - execution1.trace().setProperty("b","b4"); - execution1.trace().logValue("b","b4"); + execution1.trace().setProperty("b", "b4"); + execution1.trace().logValue("b", "b4"); - Execution execution3=new Execution(chain,execution1); - execution3.trace().setProperty("b","b5"); - execution3.trace().setProperty("c","c1"); - execution3.trace().logValue("b","b5"); - execution3.trace().logValue("c","c1"); + Execution execution3 = new Execution(chain, execution1); + execution3.trace().setProperty("b", "b5"); + execution3.trace().setProperty("c", "c1"); + execution3.trace().logValue("b", "b5"); + execution3.trace().logValue("c", "c1"); execution3.trace().trace(" child-2 1", 2); - execution2.trace().setProperty("c","c2"); - execution2.trace().logValue("c","c2"); + execution2.trace().setProperty("c", "c2"); + execution2.trace().logValue("c", "c2"); execution1.trace().trace("root 2", 2); execution3.trace().setProperty("d", "d1"); - execution1.trace().logValue("d","d1"); + execution1.trace().logValue("d", "d1"); execution2.trace().trace(" child-1 2", 2); execution2.trace().setProperty("c", "c3"); - execution2.trace().logValue("c","c3"); + execution2.trace().logValue("c", "c3"); - execution1.trace().setProperty("c","c4"); - execution1.trace().logValue("c","c4"); + execution1.trace().setProperty("c", "c4"); + execution1.trace().logValue("c", "c4"); - Iterator<String> traceIterator=execution1.trace().traceNode().root().descendants(String.class).iterator(); - assertEquals("root 1",traceIterator.next()); - assertEquals(" child-1 1",traceIterator.next()); - assertEquals(" child-1 2",traceIterator.next()); - assertEquals(" child-2 1",traceIterator.next()); - assertEquals("root 2",traceIterator.next()); + Iterator<String> traceIterator = execution1.trace().traceNode().root().descendants(String.class).iterator(); + assertEquals("root 1", traceIterator.next()); + assertEquals(" child-1 1", traceIterator.next()); + assertEquals(" child-1 2", traceIterator.next()); + assertEquals(" child-2 1", traceIterator.next()); + assertEquals("root 2", traceIterator.next()); assertFalse(traceIterator.hasNext()); // Verify context variables @@ -82,10 +79,10 @@ public class ExecutionContextTestCase { assertNull(execution1.trace().getProperty("e")); // Verify access log - Set<String> logValues=new HashSet<>(); - for (Iterator<Execution.Trace.LogValue> logValueIterator=execution1.trace().logValueIterator(); logValueIterator.hasNext(); ) + Set<String> logValues = new HashSet<>(); + for (Iterator<Execution.Trace.LogValue> logValueIterator = execution1.trace().logValueIterator(); logValueIterator.hasNext(); ) logValues.add(logValueIterator.next().toString()); - assertEquals(12,logValues.size()); + assertEquals(12, logValues.size()); assertTrue(logValues.contains("a=a1")); assertTrue(logValues.contains("a=a2")); assertTrue(logValues.contains("b=b1")); diff --git a/container-core/src/test/java/com/yahoo/processing/execution/test/FutureDataTestCase.java b/container-core/src/test/java/com/yahoo/processing/execution/test/FutureDataTestCase.java index 7dd043383a1..e346628452c 100644 --- a/container-core/src/test/java/com/yahoo/processing/execution/test/FutureDataTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/execution/test/FutureDataTestCase.java @@ -7,14 +7,14 @@ import com.yahoo.processing.Request; import com.yahoo.processing.Response; import com.yahoo.processing.execution.Execution; import com.yahoo.processing.response.DataList; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import static com.yahoo.processing.test.ProcessorLibrary.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests scenarios where a data producer returns a promise of some future data rather than the data itself. @@ -27,92 +27,92 @@ public class FutureDataTestCase { /** Run a chain which ends in a processor which returns a response containing future data. */ @SuppressWarnings({"unchecked"}) @Test - public void testFutureDataPassThrough() throws InterruptedException, ExecutionException, TimeoutException { + void testFutureDataPassThrough() throws InterruptedException, ExecutionException, TimeoutException { // Set up - FutureDataSource futureDataSource=new FutureDataSource(); - Chain<Processor> chain=new Chain<>(new DataCounter(),futureDataSource); + FutureDataSource futureDataSource = new FutureDataSource(); + Chain<Processor> chain = new Chain<>(new DataCounter(), futureDataSource); // Execute - Request request=new Request(); - Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request); // Urk ... + Request request = new Request(); + Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); // Urk ... // Verify the result prior to completion of delayed data - assertEquals(1,response.data().asList().size()); - assertEquals("Data count: 0",response.data().get(0).toString()); + assertEquals(1, response.data().asList().size()); + assertEquals("Data count: 0", response.data().get(0).toString()); // complete delayed data - assertEquals("Delayed data was requested once", 1, futureDataSource.incomingData.size()); + assertEquals(1, futureDataSource.incomingData.size(), "Delayed data was requested once"); futureDataSource.incomingData.get(0).add(new StringData(request, "d1")); futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2")); - assertEquals("New data is not visible because we haven't asked for it", 1, response.data().asList().size()); + assertEquals(1, response.data().asList().size(), "New data is not visible because we haven't asked for it"); response.data().completeFuture().get(1000, TimeUnit.MILLISECONDS); - assertEquals("Now the data is available", 3, response.data().asList().size()); - assertEquals("d1",response.data().get(1).toString().toString()); - assertEquals("d2",response.data().get(2).toString().toString()); + assertEquals(3, response.data().asList().size(), "Now the data is available"); + assertEquals("d1", response.data().get(1).toString().toString()); + assertEquals("d2", response.data().get(2).toString().toString()); } /** Federate to one source which returns data immediately and one who return future data */ @SuppressWarnings({"unchecked"}) @Test - public void testFederateSyncAndAsyncData() throws InterruptedException, ExecutionException, TimeoutException { + void testFederateSyncAndAsyncData() throws InterruptedException, ExecutionException, TimeoutException { // Set up - FutureDataSource futureDataSource=new FutureDataSource(); - Chain<Processor> chain=new Chain<>(new DataCounter(),new Federator(new Chain<>(new DataSource()),new Chain<>(futureDataSource))); + FutureDataSource futureDataSource = new FutureDataSource(); + Chain<Processor> chain = new Chain<>(new DataCounter(), new Federator(new Chain<>(new DataSource()), new Chain<>(futureDataSource))); // Execute - Request request=new Request(); - request.properties().set("appendage",1); - Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + request.properties().set("appendage", 1); + Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); // Verify the result prior to completion of delayed data - assertEquals(3,response.data().asList().size()); // The sync data list + the (currently empty) future data list) + the data count - DataList syncData=(DataList)response.data().get(0); - DataList asyncData=(DataList)response.data().get(1); - StringData countData=(StringData)response.data().get(2); + assertEquals(3, response.data().asList().size()); // The sync data list + the (currently empty) future data list) + the data count + DataList syncData = (DataList) response.data().get(0); + DataList asyncData = (DataList) response.data().get(1); + StringData countData = (StringData) response.data().get(2); - assertEquals("The sync data is available",3,syncData.asList().size()); - assertEquals( "first.1",syncData.get(0).toString()); + assertEquals(3, syncData.asList().size(), "The sync data is available"); + assertEquals("first.1", syncData.get(0).toString()); assertEquals("second.1", syncData.get(1).toString()); - assertEquals( "third.1",syncData.get(2).toString()); - assertEquals("No async data yet",0,asyncData.asList().size()); - assertEquals("The data counter has run and accessed the sync data","Data count: 3",countData.toString()); + assertEquals("third.1", syncData.get(2).toString()); + assertEquals(0, asyncData.asList().size(), "No async data yet"); + assertEquals("Data count: 3", countData.toString(), "The data counter has run and accessed the sync data"); // complete async data futureDataSource.incomingData.get(0).add(new StringData(request, "d1")); futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2")); - assertEquals("New data is not visible because we haven't asked for it", 0, asyncData.asList().size()); + assertEquals(0, asyncData.asList().size(), "New data is not visible because we haven't asked for it"); asyncData.completeFuture().get(1000, TimeUnit.MILLISECONDS); - assertEquals("Now the data is available", 2, asyncData.asList().size()); - assertEquals("d1",asyncData.get(0).toString().toString()); + assertEquals(2, asyncData.asList().size(), "Now the data is available"); + assertEquals("d1", asyncData.get(0).toString().toString()); assertEquals("d2", asyncData.get(1).toString().toString()); } /** Register a chain which will be called when some async data is available */ @SuppressWarnings({"unchecked", "removal"}) @Test - public void testAsyncDataProcessing() throws InterruptedException, ExecutionException, TimeoutException { + void testAsyncDataProcessing() throws InterruptedException, ExecutionException, TimeoutException { // Set up - FutureDataSource futureDataSource=new FutureDataSource(); - Chain<Processor> asyncChain=new Chain<Processor>(new DataCounter()); - Chain<Processor> chain=new Chain<>(new AsyncDataProcessingInitiator(asyncChain),futureDataSource); + FutureDataSource futureDataSource = new FutureDataSource(); + Chain<Processor> asyncChain = new Chain<Processor>(new DataCounter()); + Chain<Processor> chain = new Chain<>(new AsyncDataProcessingInitiator(asyncChain), futureDataSource); // Execute - Request request=new Request(); - Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); // Verify the result prior to completion of delayed data - assertEquals("No data yet",0,response.data().asList().size()); + assertEquals(0, response.data().asList().size(), "No data yet"); // complete async data futureDataSource.incomingData.get(0).add(new StringData(request, "d1")); - assertEquals("New data is not visible because it is not complete", 0, response.data().asList().size()); + assertEquals(0, response.data().asList().size(), "New data is not visible because it is not complete"); futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2")); - assertEquals("Not visible because it has not been synced yet", 0, response.data().asList().size()); + assertEquals(0, response.data().asList().size(), "Not visible because it has not been synced yet"); response.data().completeFuture().get(1000, TimeUnit.MILLISECONDS); - assertEquals("Now the data as well as the count is available", 3, response.data().asList().size()); - assertEquals("d1",response.data().get(0).toString().toString()); - assertEquals("d2",response.data().get(1).toString().toString()); - assertEquals("Data count: 2",response.data().get(2).toString()); + assertEquals(3, response.data().asList().size(), "Now the data as well as the count is available"); + assertEquals("d1", response.data().get(0).toString().toString()); + assertEquals("d2", response.data().get(1).toString().toString()); + assertEquals("Data count: 2", response.data().get(2).toString()); } /** @@ -122,52 +122,51 @@ public class FutureDataTestCase { */ @SuppressWarnings({"unchecked"}) @Test - public void testAsyncDataProcessingOfFederatedResult() throws InterruptedException, ExecutionException, TimeoutException { + void testAsyncDataProcessingOfFederatedResult() throws InterruptedException, ExecutionException, TimeoutException { // Set up // Source 1 (async with completion chain) - FutureDataSource futureSource1=new FutureDataSource(); - Chain<Processor> asyncChainSource1=new Chain<Processor>(new DataCounter("source1")); - Chain<Processor> chainSource1=new Chain<>(new AsyncDataProcessingInitiator(asyncChainSource1),futureSource1); + FutureDataSource futureSource1 = new FutureDataSource(); + Chain<Processor> asyncChainSource1 = new Chain<Processor>(new DataCounter("source1")); + Chain<Processor> chainSource1 = new Chain<>(new AsyncDataProcessingInitiator(asyncChainSource1), futureSource1); // Source 2 (async source) - FutureDataSource futureSource2=new FutureDataSource(); - Chain<Processor> chainSource2=new Chain<Processor>(futureSource2); + FutureDataSource futureSource2 = new FutureDataSource(); + Chain<Processor> chainSource2 = new Chain<Processor>(futureSource2); // Source 3 (sync source) - Chain<Processor> chainSource3=new Chain<Processor>(new DataSource()); + Chain<Processor> chainSource3 = new Chain<Processor>(new DataSource()); // Main chain federating to the above - not waiting for source 1 and 2 but invoking asyncMain when both are complete - Chain<Processor> asyncMain=new Chain<Processor>(new DataCounter("main")); - Chain<Processor> main=new Chain<>(new AsyncDataProcessingInitiator(asyncMain),new Federator(chainSource1,chainSource2,chainSource3)); + Chain<Processor> asyncMain = new Chain<Processor>(new DataCounter("main")); + Chain<Processor> main = new Chain<>(new AsyncDataProcessingInitiator(asyncMain), new Federator(chainSource1, chainSource2, chainSource3)); // Execute - Request request=new Request(); - Response response=Execution.createRoot(main,0,Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request); // Verify the result prior to completion of delayed data - assertEquals("We have the sync data plus placeholders for the async lists",3,response.data().asList().size()); - DataList source1Data=((DataList)response.data().get(0)); - DataList source2Data=((DataList)response.data().get(1)); - DataList source3Data=((DataList)response.data().get(2)); + assertEquals(3, response.data().asList().size(), "We have the sync data plus placeholders for the async lists"); + DataList source1Data = ((DataList) response.data().get(0)); + DataList source2Data = ((DataList) response.data().get(1)); + DataList source3Data = ((DataList) response.data().get(2)); - assertEquals("No data yet",0,source1Data.asList().size()); - assertEquals("No data yet",0,source2Data.asList().size()); - assertEquals(3,source3Data.asList().size()); + assertEquals(0, source1Data.asList().size(), "No data yet"); + assertEquals(0, source2Data.asList().size(), "No data yet"); + assertEquals(3, source3Data.asList().size()); // complete async data in source1 - futureSource1.incomingData.get(0).addLast(new StringData(request,"source1Data")); - assertEquals("Not visible yet", 0, source1Data.asList().size()); + futureSource1.incomingData.get(0).addLast(new StringData(request, "source1Data")); + assertEquals(0, source1Data.asList().size(), "Not visible yet"); source1Data.completeFuture().get(1000, TimeUnit.MILLISECONDS); assertEquals(2, source1Data.asList().size()); - assertEquals("source1Data",source1Data.get(0).toString()); - assertEquals("Completion listener chain on this has run", "[source1] Data count: 1", source1Data.get(1).toString()); + assertEquals("source1Data", source1Data.get(0).toString()); + assertEquals("[source1] Data count: 1", source1Data.get(1).toString(), "Completion listener chain on this has run"); // source2 & main completion - assertEquals("Main completion listener has not run", 3, response.data().asList().size()); + assertEquals(3, response.data().asList().size(), "Main completion listener has not run"); futureSource2.incomingData.get(0).addLast(new StringData(request, "source2Data")); - assertEquals("Main completion listener has not run", 3, response.data().asList().size()); + assertEquals(3, response.data().asList().size(), "Main completion listener has not run"); Response.recursiveFuture(response.data()).get(); - assertEquals("Main completion listener has run", 4, response.data().asList().size()); - assertEquals("The main data counter saw all sync data, but not source2 data as it executes after this", - "[main] Data count: " + (2 + 0 + 3), response.data().get(3).toString()); + assertEquals(4, response.data().asList().size(), "Main completion listener has run"); + assertEquals("[main] Data count: " + (2 + 0 + 3), response.data().get(3).toString(), "The main data counter saw all sync data, but not source2 data as it executes after this"); } } diff --git a/container-core/src/test/java/com/yahoo/processing/execution/test/StreamingTestCase.java b/container-core/src/test/java/com/yahoo/processing/execution/test/StreamingTestCase.java index d494e774f8e..557bef39276 100644 --- a/container-core/src/test/java/com/yahoo/processing/execution/test/StreamingTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/execution/test/StreamingTestCase.java @@ -10,13 +10,13 @@ import com.yahoo.processing.execution.Execution; import com.yahoo.processing.response.Data; import com.yahoo.processing.response.IncomingData; import com.yahoo.processing.test.ProcessorLibrary; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests listening on every available new piece of data in a response @@ -28,48 +28,48 @@ public class StreamingTestCase { /** Tests adding a chain which is called every time new data is added to a data list */ @SuppressWarnings({"unchecked"}) @Test - public void testStreamingData() throws InterruptedException, ExecutionException, TimeoutException { + void testStreamingData() throws InterruptedException, ExecutionException, TimeoutException { // Set up StreamProcessor streamProcessor = new StreamProcessor(); Chain<Processor> streamProcessing = new Chain<Processor>(streamProcessor); - ProcessorLibrary.FutureDataSource futureDataSource=new ProcessorLibrary.FutureDataSource(); - Chain<Processor> main=new Chain<>(new ProcessorLibrary.DataCounter(), - new ProcessorLibrary.StreamProcessingInitiator(streamProcessing), - futureDataSource); + ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource(); + Chain<Processor> main = new Chain<>(new ProcessorLibrary.DataCounter(), + new ProcessorLibrary.StreamProcessingInitiator(streamProcessing), + futureDataSource); // Execute - Request request=new Request(); - Response response= Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request); IncomingData incomingData = futureDataSource.incomingData.get(0); // State prior to receiving any additional data - assertEquals(1,response.data().asList().size()); - assertEquals("Data count: 0",response.data().get(0).toString()); - assertEquals("Add data listener invoked also for DataCounter", 1, streamProcessor.invocationCount); - assertEquals("Initial data count", 1, response.data().asList().size()); + assertEquals(1, response.data().asList().size()); + assertEquals("Data count: 0", response.data().get(0).toString()); + assertEquals(1, streamProcessor.invocationCount, "Add data listener invoked also for DataCounter"); + assertEquals(1, response.data().asList().size(), "Initial data count"); // add first data - we have no listener so the data is held in the incoming buffer incomingData.add(new ProcessorLibrary.StringData(request, "d1")); - assertEquals("Data add listener not invoked as we are not listening on new data yet",1, streamProcessor.invocationCount); - assertEquals("New data is not consumed", 1, response.data().asList().size()); + assertEquals(1, streamProcessor.invocationCount, "Data add listener not invoked as we are not listening on new data yet"); + assertEquals(1, response.data().asList().size(), "New data is not consumed"); // start listening on incoming data - this is what a renderer will do incomingData.addNewDataListener(new MockNewDataListener(incomingData), MoreExecutors.directExecutor()); - assertEquals("We got a data add event for the data which was already added", 2, streamProcessor.invocationCount); - assertEquals("New data is consumed", 2, response.data().asList().size()); + assertEquals(2, streamProcessor.invocationCount, "We got a data add event for the data which was already added"); + assertEquals(2, response.data().asList().size(), "New data is consumed"); incomingData.add(new ProcessorLibrary.StringData(request, "d2")); - assertEquals("We are now getting data add events each time", 3, streamProcessor.invocationCount); - assertEquals("New data is consumed", 3, response.data().asList().size()); + assertEquals(3, streamProcessor.invocationCount, "We are now getting data add events each time"); + assertEquals(3, response.data().asList().size(), "New data is consumed"); incomingData.addLast(new ProcessorLibrary.StringData(request, "d3")); - assertEquals("We are getting data add events also the last time", 4, streamProcessor.invocationCount); - assertEquals("New data is consumed", 4, response.data().asList().size()); + assertEquals(4, streamProcessor.invocationCount, "We are getting data add events also the last time"); + assertEquals(4, response.data().asList().size(), "New data is consumed"); response.data().completeFuture().get(1000, TimeUnit.MILLISECONDS); // no-op here - assertEquals("d1",response.data().get(1).toString().toString()); - assertEquals("d2",response.data().get(2).toString().toString()); - assertEquals("d3",response.data().get(3).toString().toString()); + assertEquals("d1", response.data().get(1).toString().toString()); + assertEquals("d2", response.data().get(2).toString().toString()); + assertEquals("d3", response.data().get(3).toString().toString()); } private static class MockNewDataListener implements Runnable { diff --git a/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java b/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java index baed2ccdcc8..70bae6c97b1 100644 --- a/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/handler/ProcessingHandlerTestCase.java @@ -21,9 +21,9 @@ import com.yahoo.processing.rendering.Renderer; import com.yahoo.processing.request.ErrorMessage; import com.yahoo.processing.response.Data; import com.yahoo.processing.test.ProcessorLibrary; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; @@ -39,12 +39,7 @@ import java.util.concurrent.ExecutionException; import static com.yahoo.jdisc.http.server.jetty.AccessLoggingRequestHandler.CONTEXT_KEY_ACCESS_LOG_ENTRY; import static com.yahoo.processing.test.ProcessorLibrary.MapData; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Tests processing handler scenarios end to end. @@ -74,13 +69,13 @@ public class ProcessingHandlerTestCase { new Chain<>("log-value", new ProcessorLibrary.LogValueAdder(LOG_KEY, LOG_VALUE)); - @After + @AfterEach public void shutDown() { driver.close(); } @Test - public void processing_handler_stores_trace_log_values_in_the_access_log_entry() { + void processing_handler_stores_trace_log_values_in_the_access_log_entry() { driver = new ProcessingTestDriver(logValueChain); Request request = HttpRequest.newServerRequest(driver.jDiscDriver(), URI.create("http://localhost/?chain=log-value"), HttpRequest.Method.GET); AccessLogEntry entry = new AccessLogEntry(); @@ -95,7 +90,7 @@ public class ProcessingHandlerTestCase { } @Test - public void testProcessingHandlerResolvesChains() { + void testProcessingHandlerResolvesChains() { List<Chain<Processor>> chains = new ArrayList<>(); chains.add(defaultChain); chains.add(simpleChain); @@ -106,16 +101,16 @@ public class ProcessingHandlerTestCase { } @Test - public void testProcessingHandlerPropagatesRequestParametersAndContext() { + void testProcessingHandlerPropagatesRequestParametersAndContext() { List<Chain<Processor>> chains = new ArrayList<>(); chains.add(new Chain<>("default", new RequestPropertyTracer())); driver = new ProcessingTestDriver(chains); - assertTrue("JDisc request context is propagated to properties()", - driver.sendRequest("http://localhost/?chain=default&tracelevel=4").readAll().contains("context.contextVariable: '37'")); + assertTrue(driver.sendRequest("http://localhost/?chain=default&tracelevel=4").readAll().contains("context.contextVariable: '37'"), + "JDisc request context is propagated to properties()"); } @Test - public void testProcessingHandlerOutputsTrace() { + void testProcessingHandlerOutputsTrace() { List<Chain<Processor>> chains = new ArrayList<>(); chains.add(defaultChain); driver = new ProcessingTestDriver(chains); @@ -128,28 +123,28 @@ public class ProcessingHandlerTestCase { } @Test - public void testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData() { + void testProcessingHandlerTransfersErrorsToHttpStatusCodesNoData() { List<Chain<Processor>> chains = new ArrayList<>(); chains.add(simpleChain); - chains.add(new Chain<>("moved_permanently", new ProcessorLibrary.ErrorAdder(new ErrorMessage(301,"Message")))); - chains.add(new Chain<>("unauthorized", new ProcessorLibrary.ErrorAdder(new ErrorMessage(401,"Message")))); - chains.add(new Chain<>("unauthorized_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code,"Message")))); - chains.add(new Chain<>("forbidden", new ProcessorLibrary.ErrorAdder(new ErrorMessage(403,"Message")))); - chains.add(new Chain<>("forbidden_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message")))); - chains.add(new Chain<>("not_found", new ProcessorLibrary.ErrorAdder(new ErrorMessage(404,"Message")))); - chains.add(new Chain<>("not_found_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code,"Message")))); - chains.add(new Chain<>("too_many_requests", new ProcessorLibrary.ErrorAdder(new ErrorMessage(429,"Message")))); - chains.add(new Chain<>("bad_request", new ProcessorLibrary.ErrorAdder(new ErrorMessage(400,"Message")))); - chains.add(new Chain<>("bad_request_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code,"Message")))); - chains.add(new Chain<>("internal_server_error", new ProcessorLibrary.ErrorAdder(new ErrorMessage(500,"Message")))); - chains.add(new Chain<>("internal_server_error_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code,"Message")))); - chains.add(new Chain<>("service_unavailable", new ProcessorLibrary.ErrorAdder(new ErrorMessage(503,"Message")))); - chains.add(new Chain<>("service_unavailable_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code,"Message")))); - chains.add(new Chain<>("gateway_timeout", new ProcessorLibrary.ErrorAdder(new ErrorMessage(504,"Message")))); - chains.add(new Chain<>("gateway_timeout_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code,"Message")))); - chains.add(new Chain<>("bad_gateway", new ProcessorLibrary.ErrorAdder(new ErrorMessage(502,"Message")))); - chains.add(new Chain<>("bad_gateway_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code,"Message")))); - chains.add(new Chain<>("unknown_code", new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567,"Message")))); + chains.add(new Chain<>("moved_permanently", new ProcessorLibrary.ErrorAdder(new ErrorMessage(301, "Message")))); + chains.add(new Chain<>("unauthorized", new ProcessorLibrary.ErrorAdder(new ErrorMessage(401, "Message")))); + chains.add(new Chain<>("unauthorized_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code, "Message")))); + chains.add(new Chain<>("forbidden", new ProcessorLibrary.ErrorAdder(new ErrorMessage(403, "Message")))); + chains.add(new Chain<>("forbidden_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message")))); + chains.add(new Chain<>("not_found", new ProcessorLibrary.ErrorAdder(new ErrorMessage(404, "Message")))); + chains.add(new Chain<>("not_found_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code, "Message")))); + chains.add(new Chain<>("too_many_requests", new ProcessorLibrary.ErrorAdder(new ErrorMessage(429, "Message")))); + chains.add(new Chain<>("bad_request", new ProcessorLibrary.ErrorAdder(new ErrorMessage(400, "Message")))); + chains.add(new Chain<>("bad_request_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code, "Message")))); + chains.add(new Chain<>("internal_server_error", new ProcessorLibrary.ErrorAdder(new ErrorMessage(500, "Message")))); + chains.add(new Chain<>("internal_server_error_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code, "Message")))); + chains.add(new Chain<>("service_unavailable", new ProcessorLibrary.ErrorAdder(new ErrorMessage(503, "Message")))); + chains.add(new Chain<>("service_unavailable_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code, "Message")))); + chains.add(new Chain<>("gateway_timeout", new ProcessorLibrary.ErrorAdder(new ErrorMessage(504, "Message")))); + chains.add(new Chain<>("gateway_timeout_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code, "Message")))); + chains.add(new Chain<>("bad_gateway", new ProcessorLibrary.ErrorAdder(new ErrorMessage(502, "Message")))); + chains.add(new Chain<>("bad_gateway_mapped", new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code, "Message")))); + chains.add(new Chain<>("unknown_code", new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567, "Message")))); driver = new ProcessingTestDriver(chains); assertEqualStatus(200, "http://localhost/?chain=simple"); assertEqualStatus(301, "http://localhost/?chain=moved_permanently"); @@ -174,28 +169,28 @@ public class ProcessingHandlerTestCase { } @Test - public void testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData() { + void testProcessingHandlerTransfersErrorsToHttpStatusCodesWithData() { List<Chain<Processor>> chains = new ArrayList<>(); chains.add(simpleChain); - chains.add(new Chain<>("moved_permanently", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(301,"Message")))); - chains.add(new Chain<>("unauthorized", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(401,"Message")))); - chains.add(new Chain<>("unauthorized_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code,"Message")))); - chains.add(new Chain<>("forbidden", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(403,"Message")))); - chains.add(new Chain<>("forbidden_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message")))); - chains.add(new Chain<>("not_found", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(404,"Message")))); - chains.add(new Chain<>("not_found_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code,"Message")))); - chains.add(new Chain<>("too_many_requests", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(429,"Message")))); - chains.add(new Chain<>("bad_request", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(400,"Message")))); - chains.add(new Chain<>("bad_request_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code,"Message")))); - chains.add(new Chain<>("internal_server_error", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(500,"Message")))); - chains.add(new Chain<>("internal_server_error_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code,"Message")))); - chains.add(new Chain<>("service_unavailable", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(503,"Message")))); - chains.add(new Chain<>("service_unavailable_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code,"Message")))); - chains.add(new Chain<>("gateway_timeout", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(504,"Message")))); - chains.add(new Chain<>("gateway_timeout_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code,"Message")))); - chains.add(new Chain<>("bad_gateway", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(502,"Message")))); - chains.add(new Chain<>("bad_gateway_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code,"Message")))); - chains.add(new Chain<>("unknown_code", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567,"Message")))); + chains.add(new Chain<>("moved_permanently", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(301, "Message")))); + chains.add(new Chain<>("unauthorized", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(401, "Message")))); + chains.add(new Chain<>("unauthorized_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.UNAUTHORIZED.code, "Message")))); + chains.add(new Chain<>("forbidden", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(403, "Message")))); + chains.add(new Chain<>("forbidden_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message")))); + chains.add(new Chain<>("not_found", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(404, "Message")))); + chains.add(new Chain<>("not_found_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NOT_FOUND.code, "Message")))); + chains.add(new Chain<>("too_many_requests", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(429, "Message")))); + chains.add(new Chain<>("bad_request", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(400, "Message")))); + chains.add(new Chain<>("bad_request_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BAD_REQUEST.code, "Message")))); + chains.add(new Chain<>("internal_server_error", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(500, "Message")))); + chains.add(new Chain<>("internal_server_error_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.INTERNAL_SERVER_ERROR.code, "Message")))); + chains.add(new Chain<>("service_unavailable", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(503, "Message")))); + chains.add(new Chain<>("service_unavailable_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.NO_BACKENDS_IN_SERVICE.code, "Message")))); + chains.add(new Chain<>("gateway_timeout", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(504, "Message")))); + chains.add(new Chain<>("gateway_timeout_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.TIMEOUT.code, "Message")))); + chains.add(new Chain<>("bad_gateway", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(502, "Message")))); + chains.add(new Chain<>("bad_gateway_mapped", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.BACKEND_COMMUNICATION_ERROR.code, "Message")))); + chains.add(new Chain<>("unknown_code", new ProcessorLibrary.StringDataAdder("Hello"), new ProcessorLibrary.ErrorAdder(new ErrorMessage(1234567, "Message")))); driver = new ProcessingTestDriver(chains); assertEqualStatus(200, "http://localhost/?chain=simple"); assertEqualStatus(301, "http://localhost/?chain=moved_permanently"); @@ -220,27 +215,27 @@ public class ProcessingHandlerTestCase { } @Test - public void testProcessorSetsResponseHeaders() throws InterruptedException { + void testProcessorSetsResponseHeaders() throws InterruptedException { ProcessingTestDriver.MockResponseHandler responseHandler = null; try { - Map<String,List<String>> responseHeaders = new HashMap<>(); + Map<String, List<String>> responseHeaders = new HashMap<>(); responseHeaders.put("foo", List.of("fooValue")); responseHeaders.put("bar", List.of("barValue", "bazValue")); - Map<String,List<String>> otherResponseHeaders = new HashMap<>(); + Map<String, List<String>> otherResponseHeaders = new HashMap<>(); otherResponseHeaders.put("foo", List.of("fooValue2")); otherResponseHeaders.put("bax", List.of("baxValue")); List<Chain<Processor>> chains = new ArrayList<>(); - chains.add(new Chain<>("default",new ResponseHeaderSetter(responseHeaders), - new ResponseHeaderSetter(otherResponseHeaders))); + chains.add(new Chain<>("default", new ResponseHeaderSetter(responseHeaders), + new ResponseHeaderSetter(otherResponseHeaders))); driver = new ProcessingTestDriver(chains); responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse(); Response response = responseHandler.getResponse(); - assertEquals("[fooValue2, fooValue]",response.headers().get("foo").toString()); + assertEquals("[fooValue2, fooValue]", response.headers().get("foo").toString()); assertEquals("[barValue, bazValue]", response.headers().get("bar").toString()); assertEquals("[baxValue]", response.headers().get("bax").toString()); - assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read()); + assertEquals("{\"datalist\":[]}", responseHandler.read(), "ResponseHeaders are not rendered"); } finally { if (responseHandler != null) @@ -249,7 +244,7 @@ public class ProcessingHandlerTestCase { } @Test - public void testResponseDataStatus() throws InterruptedException { + void testResponseDataStatus() throws InterruptedException { ProcessingTestDriver.MockResponseHandler responseHandler = null; try { List<Chain<Processor>> chains = new ArrayList<>(); @@ -258,7 +253,7 @@ public class ProcessingHandlerTestCase { responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse(); Response response = responseHandler.getResponse(); assertEquals(429, response.getStatus()); - assertEquals("ResponseHeaders are not rendered", "{\"datalist\":[]}", responseHandler.read()); + assertEquals("{\"datalist\":[]}", responseHandler.read(), "ResponseHeaders are not rendered"); } finally { if (responseHandler != null) @@ -268,13 +263,13 @@ public class ProcessingHandlerTestCase { /** Tests that the ResponseStatus takes precedence over errors */ @Test - public void testResponseDataStatusOverridesErrors() throws InterruptedException { + void testResponseDataStatusOverridesErrors() throws InterruptedException { ProcessingTestDriver.MockResponseHandler responseHandler = null; try { List<Chain<Processor>> chains = new ArrayList<>(); chains.add(new Chain<>("default", new ResponseStatusSetter(200), - new ProcessorLibrary.StringDataAdder("Hello"), - new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code,"Message")))); + new ProcessorLibrary.StringDataAdder("Hello"), + new ProcessorLibrary.ErrorAdder(new ErrorMessage(Error.FORBIDDEN.code, "Message")))); driver = new ProcessingTestDriver(chains); responseHandler = driver.sendRequest("http://localhost/?chain=default").awaitResponse(); Response response = responseHandler.getResponse(); @@ -304,14 +299,14 @@ public class ProcessingHandlerTestCase { @SuppressWarnings("unchecked") @Test - public void testProcessingHandlerSupportsAsyncRendering() { + void testProcessingHandlerSupportsAsyncRendering() { // Set up ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource(); Chain<Processor> asyncCompletionChain = new Chain<>("asyncCompletion", new ProcessorLibrary.DataCounter("async")); Chain<Processor> chain = new Chain<>("federation", new ProcessorLibrary.DataCounter("sync"), - new ProcessorLibrary.Federator(new Chain<Processor>(new ProcessorLibrary.DataSource()), - new Chain<>(new ProcessorLibrary.AsyncDataProcessingInitiator(asyncCompletionChain),futureDataSource))); + new ProcessorLibrary.Federator(new Chain<Processor>(new ProcessorLibrary.DataSource()), + new Chain<>(new ProcessorLibrary.AsyncDataProcessingInitiator(asyncCompletionChain), futureDataSource))); List<Chain<Processor>> chains = new ArrayList<>(); chains.add(chain); driver = new ProcessingTestDriver(chains); @@ -320,46 +315,46 @@ public class ProcessingHandlerTestCase { String synchronousResponse = responseHandler.read(); assertEquals( "{\"datalist\":[" + - "{\"datalist\":[" + - "{\"data\":\"first.null\"}," + - "{\"data\":\"second.null\"}," + - "{\"data\":\"third.null\"}" + - "]}", + "{\"datalist\":[" + + "{\"data\":\"first.null\"}," + + "{\"data\":\"second.null\"}," + + "{\"data\":\"third.null\"}" + + "]}", synchronousResponse); - assertEquals("No more data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No more data is available at this point"); // Now, complete async data futureDataSource.incomingData.get(0).add(new ProcessorLibrary.StringData(null, "d1")); assertEquals( - "," + - "{\"datalist\":[" + - "{\"data\":\"d1\"}", - responseHandler.read()); + "," + + "{\"datalist\":[" + + "{\"data\":\"d1\"}", + responseHandler.read()); futureDataSource.incomingData.get(0).addLast(new ProcessorLibrary.StringData(null, "d2")); // ... which leads to the rest of the response becoming available assertEquals( - "," + - "{\"data\":\"d2\"}," + - "{\"data\":\"[async] Data count: 2\"}" + - "]}", + "," + + "{\"data\":\"d2\"}," + + "{\"data\":\"[async] Data count: 2\"}" + + "]}", responseHandler.read()); assertEquals(",{\"data\":\"[sync] Data count: 3\"}" + // Async items not counted as they arrive after chain completion - "]}", - responseHandler.read()); - assertNull("Transmission completed", responseHandler.read()); + "]}", + responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } @SuppressWarnings("unchecked") @Test - public void testProcessingHandlerSupportsAsyncUnorderedRendering() { + void testProcessingHandlerSupportsAsyncUnorderedRendering() { // Set up ProcessorLibrary.FutureDataSource futureDataSource1 = new ProcessorLibrary.FutureDataSource(); ProcessorLibrary.FutureDataSource futureDataSource2 = new ProcessorLibrary.FutureDataSource(); Chain<Processor> chain = new Chain<>("federation", - new ProcessorLibrary.Federator(false,new Chain<Processor>(futureDataSource1), - new Chain<Processor>(futureDataSource2))); + new ProcessorLibrary.Federator(false, new Chain<Processor>(futureDataSource1), + new Chain<Processor>(futureDataSource2))); List<Chain<Processor>> chains = new ArrayList<>(); chains.add(chain); driver = new ProcessingTestDriver(chains); @@ -368,69 +363,69 @@ public class ProcessingHandlerTestCase { assertEquals( "{\"datalist\":[", responseHandler.read()); - assertEquals("No more data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No more data is available at this point"); // Complete second async data first futureDataSource2.incomingData.get(0).addLast(new ProcessorLibrary.StringData(null, "d2")); assertEquals( - "{\"datalist\":[" + - "{\"data\":\"d2\"}"+ - "]}", - responseHandler.read()); + "{\"datalist\":[" + + "{\"data\":\"d2\"}" + + "]}", + responseHandler.read()); // Now complete first async data (which is therefore rendered last) futureDataSource1.incomingData.get(0).addLast(new ProcessorLibrary.StringData(null, "d1")); assertEquals( - "," + - "{\"datalist\":[" + - "{\"data\":\"d1\"}"+ - "]}", - responseHandler.read()); + "," + + "{\"datalist\":[" + + "{\"data\":\"d1\"}" + + "]}", + responseHandler.read()); assertEquals( - "]}", - responseHandler.read()); + "]}", + responseHandler.read()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } @SuppressWarnings("unchecked") @Test - public void testAsyncOnlyRendering() throws Exception { + void testAsyncOnlyRendering() throws Exception { // Set up ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource(); Chain<Processor> chain = new Chain<>("main", List.of(futureDataSource)); driver = new ProcessingTestDriver(chain); ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main"); - assertEquals("No data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No data is available at this point"); futureDataSource.incomingData.get().add(new ProcessorLibrary.StringData(null, "d1")); assertEquals( - "{\"datalist\":[" + - "{\"data\":\"d1\"}", - responseHandler.read()); + "{\"datalist\":[" + + "{\"data\":\"d1\"}", + responseHandler.read()); futureDataSource.incomingData.get().addLast(new ProcessorLibrary.StringData(null, "d2")); assertEquals( "," + - "{\"data\":\"d2\"}" + - "]}", + "{\"data\":\"d2\"}" + + "]}", responseHandler.read()); assertEquals(200, responseHandler.getStatus()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } @SuppressWarnings("unchecked") @Test - public void testAsyncRenderingWithClientClose() throws Exception { + void testAsyncRenderingWithClientClose() throws Exception { // Set up ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource(); Chain<Processor> chain = new Chain<>("main", List.of(futureDataSource)); driver = new ProcessingTestDriver(chain); ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main"); - assertEquals("No data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No data is available at this point"); futureDataSource.incomingData.get().add(new ProcessorLibrary.StringData(null, "d1")); assertEquals( @@ -443,24 +438,24 @@ public class ProcessingHandlerTestCase { assertNull(responseHandler.read()); assertEquals(200, responseHandler.getStatus()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } @SuppressWarnings("unchecked") @Test - public void testAsyncOnlyRenderingWithAsyncPostData() throws Exception { + void testAsyncOnlyRenderingWithAsyncPostData() throws Exception { // Set up ProcessorLibrary.ListenableFutureDataSource futureDataSource = new ProcessorLibrary.ListenableFutureDataSource(); PostReader postReader = new PostReader(); Chain<Processor> chain = new Chain<>("main", - new ProcessorLibrary.AsyncDataProcessingInitiator(new Chain<>(postReader)), - futureDataSource); + new ProcessorLibrary.AsyncDataProcessingInitiator(new Chain<>(postReader)), + futureDataSource); driver = new ProcessingTestDriver(chain); RequestHandlerTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main", HttpRequest.Method.POST, "Hello, world!"); - assertFalse("Post data is read later, on async completion", postReader.bodyDataFuture.isDone()); - assertEquals("No data is available at this point", 0, responseHandler.available()); + assertFalse(postReader.bodyDataFuture.isDone(), "Post data is read later, on async completion"); + assertEquals(0, responseHandler.available(), "No data is available at this point"); futureDataSource.incomingData.get().add(new ProcessorLibrary.StringData(null, "d1")); assertEquals( @@ -476,10 +471,10 @@ public class ProcessingHandlerTestCase { "]}", responseHandler.read() ); - assertEquals("Data is completed, so post data is read", "Hello, world!", postReader.bodyDataFuture.get().trim()); + assertEquals("Hello, world!", postReader.bodyDataFuture.get().trim(), "Data is completed, so post data is read"); assertEquals(200, responseHandler.getStatus()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } private static class PostReader extends Processor { @@ -506,8 +501,8 @@ public class ProcessingHandlerTestCase { @SuppressWarnings("unchecked") @Test - public void testStatusAndHeadersCanBeSetAsynchronously() throws Exception { - Map<String,List<String>> responseHeaders = new HashMap<>(); + void testStatusAndHeadersCanBeSetAsynchronously() throws Exception { + Map<String, List<String>> responseHeaders = new HashMap<>(); responseHeaders.put("foo", List.of("fooValue")); responseHeaders.put("bar", List.of("barValue", "bazValue")); @@ -517,7 +512,7 @@ public class ProcessingHandlerTestCase { driver = new ProcessingTestDriver(chain); ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main"); - assertEquals("No data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No data is available at this point"); com.yahoo.processing.Request request = futureDataSource.incomingData.get().getOwner().request(); futureDataSource.incomingData.get().addLast(new ProcessorLibrary.StringData(request, "d1")); @@ -527,12 +522,12 @@ public class ProcessingHandlerTestCase { assertEquals(500, responseHandler.getStatus()); assertEquals("[fooValue]", responseHandler.getResponse().headers().get("foo").toString()); assertEquals("[barValue, bazValue]", responseHandler.getResponse().headers().get("bar").toString()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } @SuppressWarnings("unchecked") @Test - public void testAsyncRenderingDoesNotHoldThreads() { + void testAsyncRenderingDoesNotHoldThreads() { // Set up ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource(); // Add some sync data as well to cause rendering to start before async data is added. @@ -545,11 +540,11 @@ public class ProcessingHandlerTestCase { ProcessingTestDriver.MockResponseHandler[] responseHandler = new ProcessingTestDriver.MockResponseHandler[requestCount]; for (int i = 0; i < requestCount; i++) { responseHandler[i] = driver.sendRequest("http://localhost/?chain=main"); - assertEquals("Sync data is available", - "{\"datalist\":[{\"datalist\":[{\"data\":\"first.null\"},{\"data\":\"second.null\"},{\"data\":\"third.null\"}]}", - responseHandler[i].read()); + assertEquals("{\"datalist\":[{\"datalist\":[{\"data\":\"first.null\"},{\"data\":\"second.null\"},{\"data\":\"third.null\"}]}", + responseHandler[i].read(), + "Sync data is available"); } - assertEquals("All requests was processed", requestCount, futureDataSource.incomingData.size()); + assertEquals(requestCount, futureDataSource.incomingData.size(), "All requests was processed"); // Complete all for (int i = 0; i < requestCount; i++) { @@ -558,13 +553,13 @@ public class ProcessingHandlerTestCase { futureDataSource.incomingData.get(i).addLast(new ProcessorLibrary.StringData(null, "d2")); assertEquals(",{\"data\":\"d2\"}]}", responseHandler[i].read()); assertEquals("]}", responseHandler[i].read()); - assertNull("Transmission completed", responseHandler[i].read()); + assertNull(responseHandler[i].read(), "Transmission completed"); } } @SuppressWarnings("unchecked") @Test - public void testStreamedRendering() throws Exception { + void testStreamedRendering() throws Exception { // Set up Chain<Processor> streamChain = new Chain<>(new StreamProcessor()); @@ -593,26 +588,27 @@ public class ProcessingHandlerTestCase { ",{\"data\":\"map data: {streamProcessed=true}\"}]}", responseHandler.read()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } @Test - public void testEagerStreamedRenderingOnFreeze() { + void testEagerStreamedRenderingOnFreeze() { FreezingDataSource source = new FreezingDataSource(); Chain<Processor> mainChain = new Chain<>("main", source); driver = new ProcessingTestDriver(mainChain); ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main"); - assertEquals("No data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No data is available at this point"); source.freeze.set(true); assertEquals("{\"datalist\":[{\"data\":\"d1\"}", responseHandler.read()); source.addLastData.set(true); // signal completion assertEquals(",{\"data\":\"d2\"}]}", responseHandler.read()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } + // TODO @Test - @Ignore // TODO - public void testNestedEagerStreamedRenderingOnFreeze() { + @Disabled + void testNestedEagerStreamedRenderingOnFreeze() { try { FreezingDataSource source1 = new FreezingDataSource("s1"); FreezingDataSource source2 = new FreezingDataSource("s2"); @@ -625,16 +621,15 @@ public class ProcessingHandlerTestCase { new Chain<Processor>(source3))); driver = new ProcessingTestDriver(mainChain); ProcessingTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/?chain=main"); - assertEquals("No data is available at this point", 0, responseHandler.available()); + assertEquals(0, responseHandler.available(), "No data is available at this point"); source1.freeze.set(true); - assertEquals("Received because the parent list and source1 list is frozen", - "{\"datalist\":[{\"datalist\":[{\"data\":\"s1d1\"}", responseHandler.read()); + assertEquals("{\"datalist\":[{\"datalist\":[{\"data\":\"s1d1\"}", responseHandler.read(), "Received because the parent list and source1 list is frozen"); source2.addLastData.set(true); // No effect as we are working on source1, which is not completed yet assertEquals("{\"datalist\":[{\"data\":\"s1d1\"}", responseHandler.read()); source1.addLastData.set(true); // Make source 1 and 2 available assertEquals(",{\"data\":\"d2\"}]}", responseHandler.read()); - assertNull("Transmission completed", responseHandler.read()); + assertNull(responseHandler.read(), "Transmission completed"); } catch (Throwable t) { t.printStackTrace(); @@ -642,14 +637,16 @@ public class ProcessingHandlerTestCase { } } - @Test(expected = IllegalArgumentException.class) - public void testRetrievingNonExistingRendererThrows() { - driver = new ProcessingTestDriver(List.of()); - driver.processingHandler().getRendererCopy(ComponentSpecification.fromString("non-existent")); + @Test + void testRetrievingNonExistingRendererThrows() { + assertThrows(IllegalArgumentException.class, () -> { + driver = new ProcessingTestDriver(List.of()); + driver.processingHandler().getRendererCopy(ComponentSpecification.fromString("non-existent")); + }); } @Test - public void testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser() { + void testDefaultRendererIsAddedToRegistryWhenNoneIsGivenByUser() { String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID; driver = new ProcessingTestDriver(List.of()); @@ -659,7 +656,7 @@ public class ProcessingHandlerTestCase { } @Test - public void testUserSpecifiedDefaultRendererIsNotReplacedInRegistry() { + void testUserSpecifiedDefaultRendererIsNotReplacedInRegistry() { String defaultId = AbstractProcessingHandler.DEFAULT_RENDERER_ID; Renderer myDefaultRenderer = new ProcessingRenderer(); ComponentRegistry<Renderer> renderers = new ComponentRegistry<>(); diff --git a/container-core/src/test/java/com/yahoo/processing/processors/MockUserDatabaseClientTest.java b/container-core/src/test/java/com/yahoo/processing/processors/MockUserDatabaseClientTest.java index 8de08189f7a..58a490b8e80 100644 --- a/container-core/src/test/java/com/yahoo/processing/processors/MockUserDatabaseClientTest.java +++ b/container-core/src/test/java/com/yahoo/processing/processors/MockUserDatabaseClientTest.java @@ -11,30 +11,29 @@ import com.yahoo.processing.Request; import com.yahoo.processing.Response; import com.yahoo.processing.execution.Execution; import com.yahoo.processing.execution.chain.ChainRegistry; -import org.junit.After; -import org.junit.Test; -import static org.junit.Assert.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.net.URI; import java.util.Collection; import java.util.Collections; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class MockUserDatabaseClientTest { private TestDriver driver; @Test - public void testClientExampleProcessor() { - Request request=null; + void testClientExampleProcessor() { + Request request = null; try { - Chain<Processor> chain = new Chain<>("default",new MockUserDatabaseClient()); + Chain<Processor> chain = new Chain<>("default", new MockUserDatabaseClient()); setupJDisc(Collections.singletonList(chain)); request = createRequest(); Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); - MockUserDatabaseClient.User user = (MockUserDatabaseClient.User)response.data().request().properties().get("User"); + MockUserDatabaseClient.User user = (MockUserDatabaseClient.User) response.data().request().properties().get("User"); assertNotNull(user); assertEquals("foo", user.getId()); } @@ -71,7 +70,7 @@ public class MockUserDatabaseClientTest { driver.activateContainer(builder); } - @After + @AfterEach public void shutDownDisc() { assertTrue(driver.close()); } diff --git a/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java b/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java index 5dfe29dd4a1..fb8aca95d9a 100644 --- a/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java +++ b/container-core/src/test/java/com/yahoo/processing/rendering/AsynchronousSectionedRendererTest.java @@ -13,7 +13,7 @@ import com.yahoo.processing.response.Data; import com.yahoo.processing.response.DataList; import com.yahoo.processing.response.IncomingData; import com.yahoo.text.Utf8; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.OutputStream; @@ -23,9 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.*; /** * @author Einar M R Rosenvinge @@ -35,27 +33,27 @@ public class AsynchronousSectionedRendererTest { private static final Charset CHARSET = Utf8.getCharset(); @Test - public void testRenderersOfTheSamePrototypeUseTheSameExecutor() { + void testRenderersOfTheSamePrototypeUseTheSameExecutor() { TestRenderer rendererPrototype = new TestRenderer(); - TestRenderer rendererCopy1 = (TestRenderer)rendererPrototype.clone(); + TestRenderer rendererCopy1 = (TestRenderer) rendererPrototype.clone(); rendererCopy1.init(); assertSame(rendererPrototype.getRenderingExecutor(), rendererCopy1.getRenderingExecutor()); } @Test - public void testRenderersOfDifferentPrototypesUseDifferentExecutors() { + void testRenderersOfDifferentPrototypesUseDifferentExecutors() { TestRenderer rendererPrototype1 = new TestRenderer(); - TestRenderer rendererCopy1 = (TestRenderer)rendererPrototype1.clone(); + TestRenderer rendererCopy1 = (TestRenderer) rendererPrototype1.clone(); rendererCopy1.init(); TestRenderer rendererPrototype2 = new TestRenderer(); - TestRenderer rendererCopy2 = (TestRenderer)rendererPrototype2.clone(); + TestRenderer rendererCopy2 = (TestRenderer) rendererPrototype2.clone(); rendererCopy2.init(); assertNotSame(rendererPrototype1.getRenderingExecutor(), rendererCopy2.getRenderingExecutor()); } @Test - public void testAsyncSectionedRenderer() throws IOException, InterruptedException { + void testAsyncSectionedRenderer() throws IOException, InterruptedException { StringDataList dataList = createDataListWithStrangeStrings(); TestRenderer renderer = new TestRenderer(); @@ -69,7 +67,7 @@ public class AsynchronousSectionedRendererTest { } @Test - public void testEmptyProcessingRendering() throws IOException, InterruptedException { + void testEmptyProcessingRendering() throws IOException, InterruptedException { Request request = new Request(); DataList dataList = ArrayDataList.create(request); @@ -77,117 +75,117 @@ public class AsynchronousSectionedRendererTest { } @Test - public void testProcessingRendering() throws IOException, InterruptedException { + void testProcessingRendering() throws IOException, InterruptedException { StringDataList dataList = createDataListWithStrangeStrings(); assertEquals("{\"datalist\":[" + - "{\"data\":\"f\\\\o\\\"o\"}," + - "{\"datalist\":[" + - "{\"data\":\"b/a\\br\"}," + - "{\"data\":\"f\\f\\no\\ro\\tbar\\u0005\"}" + - "]}" + - "]}", + "{\"data\":\"f\\\\o\\\"o\"}," + + "{\"datalist\":[" + + "{\"data\":\"b/a\\br\"}," + + "{\"data\":\"f\\f\\no\\ro\\tbar\\u0005\"}" + + "]}" + + "]}", render(dataList)); } @Test - public void testProcessingRenderingWithErrors() throws IOException, InterruptedException { + void testProcessingRenderingWithErrors() throws IOException, InterruptedException { StringDataList dataList = createDataList(); // Add errors - dataList.request().errors().add(new ErrorMessage("m1","d1")); - dataList.request().errors().add(new ErrorMessage("m2","d2")); + dataList.request().errors().add(new ErrorMessage("m1", "d1")); + dataList.request().errors().add(new ErrorMessage("m2", "d2")); assertEquals("{\"errors\":[" + - "\"m1: d1\"," + - "\"m2: d2\"" + - "]," + - "\"datalist\":[" + - "{\"data\":\"l1\"}," + - "{\"datalist\":[" + - "{\"data\":\"l11\"}," + - "{\"data\":\"l12\"}" + - "]}" + - "]}", + "\"m1: d1\"," + + "\"m2: d2\"" + + "]," + + "\"datalist\":[" + + "{\"data\":\"l1\"}," + + "{\"datalist\":[" + + "{\"data\":\"l11\"}," + + "{\"data\":\"l12\"}" + + "]}" + + "]}", render(dataList)); } @Test - public void testProcessingRenderingWithStackTraces() throws IOException, InterruptedException { + void testProcessingRenderingWithStackTraces() throws IOException, InterruptedException { Exception exception; // Create thrown exception try { throw new RuntimeException("Thrown"); } catch (RuntimeException e) { - exception=e; + exception = e; } StringDataList dataList = createDataList(); // Add errors - dataList.request().errors().add(new ErrorMessage("m1","d1",exception)); - dataList.request().errors().add(new ErrorMessage("m2","d2")); + dataList.request().errors().add(new ErrorMessage("m1", "d1", exception)); + dataList.request().errors().add(new ErrorMessage("m2", "d2")); assertEquals( "{\"errors\":[" + - "{" + - "\"error\":\"m1: d1: Thrown\"," + - "\"stacktrace\":\"java.lang.RuntimeException: Thrown\\n\\tat com.yahoo.processing.rendering.AsynchronousSectionedRendererTest.", - render(dataList).substring(0,157)); + "{" + + "\"error\":\"m1: d1: Thrown\"," + + "\"stacktrace\":\"java.lang.RuntimeException: Thrown\\n\\tat com.yahoo.processing.rendering.AsynchronousSectionedRendererTest.", + render(dataList).substring(0, 157)); } @Test - public void testProcessingRenderingWithClonedErrorRequest() throws IOException, InterruptedException { + void testProcessingRenderingWithClonedErrorRequest() throws IOException, InterruptedException { StringDataList dataList = createDataList(); // Add errors - dataList.request().errors().add(new ErrorMessage("m1","d1")); - dataList.request().errors().add(new ErrorMessage("m2","d2")); + dataList.request().errors().add(new ErrorMessage("m1", "d1")); + dataList.request().errors().add(new ErrorMessage("m2", "d2")); dataList.add(new StringDataList(dataList.request().clone())); // Cloning a request which contains errors // ... should not cause repetition of those errors assertEquals("{\"errors\":[" + - "\"m1: d1\"," + - "\"m2: d2\"" + - "]," + - "\"datalist\":[" + - "{\"data\":\"l1\"}," + - "{\"datalist\":[" + - "{\"data\":\"l11\"}," + - "{\"data\":\"l12\"}" + - "]}," + - "{\"datalist\":[]}" + - "]}", + "\"m1: d1\"," + + "\"m2: d2\"" + + "]," + + "\"datalist\":[" + + "{\"data\":\"l1\"}," + + "{\"datalist\":[" + + "{\"data\":\"l11\"}," + + "{\"data\":\"l12\"}" + + "]}," + + "{\"datalist\":[]}" + + "]}", render(dataList)); } @Test - public void testProcessingRenderingWithClonedErrorRequestContainingNewErrors() throws IOException, InterruptedException { + void testProcessingRenderingWithClonedErrorRequestContainingNewErrors() throws IOException, InterruptedException { StringDataList dataList = createDataList(); // Add errors - dataList.request().errors().add(new ErrorMessage("m1","d1")); - dataList.request().errors().add(new ErrorMessage("m2","d2")); + dataList.request().errors().add(new ErrorMessage("m1", "d1")); + dataList.request().errors().add(new ErrorMessage("m2", "d2")); dataList.add(new StringDataList(dataList.request().clone())); // Cloning a request containing errors // and adding new errors to it - dataList.asList().get(2).request().errors().add(new ErrorMessage("m3","d3")); + dataList.asList().get(2).request().errors().add(new ErrorMessage("m3", "d3")); assertEquals("{\"errors\":[" + - "\"m1: d1\"," + - "\"m2: d2\"" + - "]," + - "\"datalist\":[" + - "{\"data\":\"l1\"}," + - "{\"datalist\":[" + - "{\"data\":\"l11\"}," + - "{\"data\":\"l12\"}" + - "]}," + - "{\"errors\":[" + - "\"m3: d3\"" + - "]," + - "\"datalist\":[]}" + - "]}", + "\"m1: d1\"," + + "\"m2: d2\"" + + "]," + + "\"datalist\":[" + + "{\"data\":\"l1\"}," + + "{\"datalist\":[" + + "{\"data\":\"l11\"}," + + "{\"data\":\"l12\"}" + + "]}," + + "{\"errors\":[" + + "\"m3: d3\"" + + "]," + + "\"datalist\":[]}" + + "]}", render(dataList)); } diff --git a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java index a8a2c76a609..055dbf77371 100644 --- a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java @@ -6,12 +6,9 @@ import com.yahoo.text.Lowercase; import java.util.Iterator; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Module local test of the basic property name building block. @@ -30,23 +27,24 @@ public class CompoundNameTestCase { void verifyStrict(String expected, CompoundName actual) { verifyStrict(new CompoundName(expected), actual); } + @Test - public final void testLast() { + final void testLast() { assertEquals(NAME.substring(NAME.lastIndexOf('.') + 1), cn.last()); } @Test - public final void testFirst() { + final void testFirst() { assertEquals(NAME.substring(0, NAME.indexOf('.')), cn.first()); } @Test - public final void testRest() { + final void testRest() { verifyStrict(NAME.substring(NAME.indexOf('.') + 1), cn.rest()); } @Test - public final void testRestN() { + final void testRestN() { verifyStrict("a.b.c.d.e", new CompoundName("a.b.c.d.e").rest(0)); verifyStrict("b.c.d.e", new CompoundName("a.b.c.d.e").rest(1)); verifyStrict("c.d.e", new CompoundName("a.b.c.d.e").rest(2)); @@ -56,7 +54,7 @@ public class CompoundNameTestCase { } @Test - public final void testPrefix() { + final void testPrefix() { assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName(""))); assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName("a"))); assertTrue(new CompoundName("a.b.c").hasPrefix(new CompoundName("a.b"))); @@ -67,13 +65,13 @@ public class CompoundNameTestCase { } @Test - public void testFromComponents() { + void testFromComponents() { verifyStrict("a", CompoundName.fromComponents("a")); verifyStrict("a.b", CompoundName.fromComponents("a", "b")); } @Test - public final void testSize() { + final void testSize() { Splitter s = Splitter.on('.'); Iterable<String> i = s.split(NAME); int n = 0; @@ -84,23 +82,23 @@ public class CompoundNameTestCase { } @Test - public final void testGet() { + final void testGet() { String s = cn.get(0); assertEquals(NAME.substring(0, NAME.indexOf('.')), s); } @Test - public final void testIsCompound() { + final void testIsCompound() { assertTrue(cn.isCompound()); } @Test - public final void testIsEmpty() { + final void testIsEmpty() { assertFalse(cn.isEmpty()); } @Test - public final void testAsList() { + final void testAsList() { List<String> l = cn.asList(); Splitter peoplesFront = Splitter.on('.'); Iterable<String> answer = peoplesFront.split(NAME); @@ -112,15 +110,15 @@ public class CompoundNameTestCase { } @Test - public final void testEqualsObject() { - assertFalse(cn.equals(NAME)); - assertFalse(cn.equals(null)); + final void testEqualsObject() { + assertNotEquals(cn, NAME); + assertNotEquals(cn, null); verifyStrict(cn, cn); verifyStrict(cn, new CompoundName(NAME)); } @Test - public final void testEmptyNonEmpty() { + final void testEmptyNonEmpty() { assertTrue(new CompoundName("").isEmpty()); assertEquals(0, new CompoundName("").size()); assertFalse(new CompoundName("a").isEmpty()); @@ -131,12 +129,12 @@ public class CompoundNameTestCase { } @Test - public final void testGetLowerCasedName() { + final void testGetLowerCasedName() { assertEquals(Lowercase.toLowerCase(NAME), cn.getLowerCasedName()); } @Test - public void testAppendCompound() { + void testAppendCompound() { verifyStrict("a.b.c.d", new CompoundName("").append(new CompoundName("a.b.c.d"))); verifyStrict("a.b.c.d", new CompoundName("a").append(new CompoundName("b.c.d"))); verifyStrict("a.b.c.d", new CompoundName("a.b").append(new CompoundName("c.d"))); @@ -145,7 +143,7 @@ public class CompoundNameTestCase { } @Test - public void empty_CompoundName_is_prefix_of_any_CompoundName() { + void empty_CompoundName_is_prefix_of_any_CompoundName() { CompoundName empty = new CompoundName(""); assertTrue(empty.hasPrefix(empty)); @@ -153,7 +151,7 @@ public class CompoundNameTestCase { } @Test - public void whole_components_must_match_to_be_prefix() { + void whole_components_must_match_to_be_prefix() { CompoundName stringPrefix = new CompoundName("a"); CompoundName name = new CompoundName("aa"); @@ -161,28 +159,28 @@ public class CompoundNameTestCase { } @Test - public void testFirstRest() { + void testFirstRest() { verifyStrict(CompoundName.empty, CompoundName.empty.rest()); - CompoundName n=new CompoundName("on.two.three"); + CompoundName n = new CompoundName("on.two.three"); assertEquals("on", n.first()); verifyStrict("two.three", n.rest()); - n=n.rest(); + n = n.rest(); assertEquals("two", n.first()); verifyStrict("three", n.rest()); - n=n.rest(); + n = n.rest(); assertEquals("three", n.first()); verifyStrict("", n.rest()); - n=n.rest(); + n = n.rest(); assertEquals("", n.first()); verifyStrict("", n.rest()); - n=n.rest(); + n = n.rest(); assertEquals("", n.first()); verifyStrict("", n.rest()); } @Test - public void testHashCodeAndEquals() { + void testHashCodeAndEquals() { CompoundName n1 = new CompoundName("venn.d.a"); CompoundName n2 = new CompoundName(n1.asList()); assertEquals(n1.hashCode(), n2.hashCode()); @@ -190,7 +188,7 @@ public class CompoundNameTestCase { } @Test - public void testAppendString() { + void testAppendString() { verifyStrict("a", new CompoundName("a").append("")); verifyStrict("a", new CompoundName("").append("a")); verifyStrict("a.b", new CompoundName("a").append("b")); @@ -203,14 +201,14 @@ public class CompoundNameTestCase { } @Test - public void testEmpty() { - CompoundName empty=new CompoundName(""); + void testEmpty() { + CompoundName empty = new CompoundName(""); assertEquals("", empty.toString()); assertEquals(0, empty.asList().size()); } @Test - public void testAsList2() { + void testAsList2() { assertEquals("[one]", new CompoundName("one").asList().toString()); assertEquals("[one, two, three]", new CompoundName("one.two.three").asList().toString()); } diff --git a/container-core/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java index fd152dccb96..1d4208fd356 100644 --- a/container-core/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/request/test/ErrorMessageTestCase.java @@ -2,10 +2,10 @@ package com.yahoo.processing.request.test; import com.yahoo.processing.request.ErrorMessage; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * @author bratseth @@ -13,49 +13,49 @@ import static org.junit.Assert.assertNotEquals; public class ErrorMessageTestCase { @Test - public void testToString() { - assertEquals("message",new ErrorMessage("message").toString()); - assertEquals("message: hello",new ErrorMessage("message",new Exception("hello")).toString()); - assertEquals("message: detail",new ErrorMessage("message","detail").toString()); - assertEquals("37: message: detail",new ErrorMessage(37,"message","detail").toString()); - assertEquals("message: detail: hello",new ErrorMessage("message","detail",new Exception("hello")).toString()); - assertEquals("message: detail: hello: world",new ErrorMessage("message","detail",new Exception("hello",new Exception("world"))).toString()); - assertEquals("message: detail: hello: Exception",new ErrorMessage("message","detail",new Exception("hello",new Exception())).toString()); - assertEquals("message: detail: hello",new ErrorMessage("message","detail",new Exception(new Exception("hello"))).toString()); - assertEquals("message: detail: java.lang.Exception: Exception",new ErrorMessage("message","detail",new Exception(new Exception())).toString()); + void testToString() { + assertEquals("message", new ErrorMessage("message").toString()); + assertEquals("message: hello", new ErrorMessage("message", new Exception("hello")).toString()); + assertEquals("message: detail", new ErrorMessage("message", "detail").toString()); + assertEquals("37: message: detail", new ErrorMessage(37, "message", "detail").toString()); + assertEquals("message: detail: hello", new ErrorMessage("message", "detail", new Exception("hello")).toString()); + assertEquals("message: detail: hello: world", new ErrorMessage("message", "detail", new Exception("hello", new Exception("world"))).toString()); + assertEquals("message: detail: hello: Exception", new ErrorMessage("message", "detail", new Exception("hello", new Exception())).toString()); + assertEquals("message: detail: hello", new ErrorMessage("message", "detail", new Exception(new Exception("hello"))).toString()); + assertEquals("message: detail: java.lang.Exception: Exception", new ErrorMessage("message", "detail", new Exception(new Exception())).toString()); } @Test - public void testAccessors() { - ErrorMessage m = new ErrorMessage(37,"message","detail",new Exception("hello")); - assertEquals(37,m.getCode()); - assertEquals("message",m.getMessage()); - assertEquals("detail",m.getDetailedMessage()); - assertEquals("hello",m.getCause().getMessage()); + void testAccessors() { + ErrorMessage m = new ErrorMessage(37, "message", "detail", new Exception("hello")); + assertEquals(37, m.getCode()); + assertEquals("message", m.getMessage()); + assertEquals("detail", m.getDetailedMessage()); + assertEquals("hello", m.getCause().getMessage()); } @Test - public void testEquality() { - assertEquals(new ErrorMessage(37,"message","detail",new Exception("hello")), - new ErrorMessage(37,"message","detail",new Exception("hello"))); - assertEquals(new ErrorMessage("message","detail",new Exception("hello")), - new ErrorMessage("message","detail",new Exception("hello"))); - assertEquals(new ErrorMessage("message",new Exception("hello")), - new ErrorMessage("message",new Exception("hello"))); + void testEquality() { + assertEquals(new ErrorMessage(37, "message", "detail", new Exception("hello")), + new ErrorMessage(37, "message", "detail", new Exception("hello"))); + assertEquals(new ErrorMessage("message", "detail", new Exception("hello")), + new ErrorMessage("message", "detail", new Exception("hello"))); + assertEquals(new ErrorMessage("message", new Exception("hello")), + new ErrorMessage("message", new Exception("hello"))); assertEquals(new ErrorMessage("message"), - new ErrorMessage("message")); - assertEquals(new ErrorMessage("message",new Exception()), - new ErrorMessage("message")); + new ErrorMessage("message")); + assertEquals(new ErrorMessage("message", new Exception()), + new ErrorMessage("message")); assertNotEquals(new ErrorMessage("message"), - new ErrorMessage("message","detail")); - assertNotEquals(new ErrorMessage(37,"message"), - new ErrorMessage("message")); - assertNotEquals(new ErrorMessage(37,"message"), - new ErrorMessage(38,"message")); - assertNotEquals(new ErrorMessage("message","detail1"), - new ErrorMessage("message","detail2")); + new ErrorMessage("message", "detail")); + assertNotEquals(new ErrorMessage(37, "message"), + new ErrorMessage("message")); + assertNotEquals(new ErrorMessage(37, "message"), + new ErrorMessage(38, "message")); + assertNotEquals(new ErrorMessage("message", "detail1"), + new ErrorMessage("message", "detail2")); assertNotEquals(new ErrorMessage("message1"), - new ErrorMessage("message2")); + new ErrorMessage("message2")); } } diff --git a/container-core/src/test/java/com/yahoo/processing/request/test/PropertyMapTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/test/PropertyMapTestCase.java index 5d7d1e63b21..de5437ab658 100644 --- a/container-core/src/test/java/com/yahoo/processing/request/test/PropertyMapTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/request/test/PropertyMapTestCase.java @@ -3,15 +3,13 @@ package com.yahoo.processing.request.test; import com.yahoo.processing.request.properties.PropertyMap; import com.yahoo.processing.request.properties.PublicCloneable; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -19,40 +17,40 @@ import static org.junit.Assert.assertTrue; public class PropertyMapTestCase { @Test - public void testObjectCloning() { + void testObjectCloning() { PropertyMap map = new PropertyMap(); map.set("clonable", new ClonableObject()); map.set("publicClonable", new PublicClonableObject()); map.set("nonclonable", new NonClonableObject()); - map.set("clonableArray", new ClonableObject[] {new ClonableObject()}); - map.set("publicClonableArray", new ClonableObject[] {new ClonableObject()}); - map.set("nonclonableArray", new NonClonableObject[] {new NonClonableObject()}); + map.set("clonableArray", new ClonableObject[]{new ClonableObject()}); + map.set("publicClonableArray", new ClonableObject[]{new ClonableObject()}); + map.set("nonclonableArray", new NonClonableObject[]{new NonClonableObject()}); map.set("clonableList", Collections.singletonList(new ClonableObject())); map.set("nonclonableList", Collections.singletonList(new NonClonableObject())); assertNotNull(map.get("clonable")); assertNotNull(map.get("nonclonable")); - PropertyMap mapClone=map.clone(); + PropertyMap mapClone = map.clone(); assertTrue(map.get("clonable") != mapClone.get("clonable")); - assertTrue(map.get("publicClonable")!= mapClone.get("publicClonable")); - assertTrue(map.get("nonclonable") == mapClone.get("nonclonable")); + assertTrue(map.get("publicClonable") != mapClone.get("publicClonable")); + assertEquals(map.get("nonclonable"), mapClone.get("nonclonable")); assertTrue(map.get("clonableArray") != mapClone.get("clonableArray")); assertTrue(first(map.get("clonableArray")) != first(mapClone.get("clonableArray"))); assertTrue(map.get("publicClonableArray") != mapClone.get("publicClonableArray")); assertTrue(first(map.get("publicClonableArray")) != first(mapClone.get("publicClonableArray"))); - assertTrue(first(map.get("nonclonableArray")) == first(mapClone.get("nonclonableArray"))); + assertEquals(first(map.get("nonclonableArray")), first(mapClone.get("nonclonableArray"))); } - + @Test - public void testArrayCloning() { + void testArrayCloning() { PropertyMap map = new PropertyMap(); - byte[] byteArray = new byte[] {2, 4, 7}; + byte[] byteArray = new byte[]{2, 4, 7}; map.set("byteArray", byteArray); PropertyMap mapClone = map.clone(); - assertArrayEquals(byteArray, (byte[])mapClone.get("byteArray")); - assertTrue("Array was cloned", mapClone.get("byteArray") != byteArray); + assertArrayEquals(byteArray, (byte[]) mapClone.get("byteArray")); + assertTrue(mapClone.get("byteArray") != byteArray, "Array was cloned"); } private Object first(Object object) { diff --git a/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java index a791c535b5d..c82b85d84d9 100644 --- a/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/request/test/RequestTestCase.java @@ -6,10 +6,10 @@ import com.yahoo.processing.request.CompoundName; import com.yahoo.processing.request.ErrorMessage; import com.yahoo.processing.request.Properties; import com.yahoo.processing.request.properties.PropertyMap; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Tests using requests @@ -21,7 +21,7 @@ public class RequestTestCase { private static final double delta = 0.0000000001; @Test - public void testProperties() { + void testProperties() { Properties p = new PropertyMap(); p.set("a", "a1"); Request r = new Request(p); @@ -39,52 +39,52 @@ public class RequestTestCase { assertNull(r.properties().get(new CompoundName("c"))); assertEquals("b1", r.properties().getString("b")); - assertEquals("b1", r.properties().getString("b","default")); - assertEquals("default", r.properties().getString("c","default")); - assertEquals(null, r.properties().getString("c")); + assertEquals("b1", r.properties().getString("b", "default")); + assertEquals("default", r.properties().getString("c", "default")); + assertNull(r.properties().getString("c")); assertEquals("b1", r.properties().getString(new CompoundName("b"))); - assertEquals("b1", r.properties().getString(new CompoundName("b"),"default")); - assertEquals("default", r.properties().getString(new CompoundName("c"),"default")); - assertEquals(null, r.properties().getString(new CompoundName("c"))); - - r.properties().set("i",7); - assertEquals(7, (int)r.properties().getInteger("i")); - assertEquals(7, (int)r.properties().getInteger("i",3)); - assertEquals(3, (int)r.properties().getInteger("n",3)); + assertEquals("b1", r.properties().getString(new CompoundName("b"), "default")); + assertEquals("default", r.properties().getString(new CompoundName("c"), "default")); + assertNull(r.properties().getString(new CompoundName("c"))); + + r.properties().set("i", 7); + assertEquals(7, (int) r.properties().getInteger("i")); + assertEquals(7, (int) r.properties().getInteger("i", 3)); + assertEquals(3, (int) r.properties().getInteger("n", 3)); assertNull(r.properties().getInteger("n")); - assertEquals(7, (int)r.properties().getInteger(new CompoundName("i"))); - assertEquals(7, (int)r.properties().getInteger(new CompoundName("i"),3)); - assertEquals(3, (int)r.properties().getInteger(new CompoundName("n"),3)); + assertEquals(7, (int) r.properties().getInteger(new CompoundName("i"))); + assertEquals(7, (int) r.properties().getInteger(new CompoundName("i"), 3)); + assertEquals(3, (int) r.properties().getInteger(new CompoundName("n"), 3)); assertNull(r.properties().getInteger("n")); r.properties().set(new CompoundName("l"), 7); assertEquals(7, (long) r.properties().getLong("l")); - assertEquals(7, (long)r.properties().getLong("l",3l)); - assertEquals(3, (long)r.properties().getLong("m",3l)); + assertEquals(7, (long) r.properties().getLong("l", 3l)); + assertEquals(3, (long) r.properties().getLong("m", 3l)); assertNull(r.properties().getInteger("m")); - assertEquals(7, (long)r.properties().getLong(new CompoundName("l"))); - assertEquals(7, (long)r.properties().getLong(new CompoundName("l"),3l)); - assertEquals(3, (long)r.properties().getLong(new CompoundName("m"),3l)); + assertEquals(7, (long) r.properties().getLong(new CompoundName("l"))); + assertEquals(7, (long) r.properties().getLong(new CompoundName("l"), 3l)); + assertEquals(3, (long) r.properties().getLong(new CompoundName("m"), 3l)); assertNull(r.properties().getInteger("m")); r.properties().set("d", 7.3); assertEquals(7.3, r.properties().getDouble("d"), delta); - assertEquals(7.3, r.properties().getDouble("d",3.4d), delta); - assertEquals(3.4, r.properties().getDouble("f",3.4d), delta); + assertEquals(7.3, r.properties().getDouble("d", 3.4d), delta); + assertEquals(3.4, r.properties().getDouble("f", 3.4d), delta); assertNull(r.properties().getDouble("f")); assertEquals(7.3, r.properties().getDouble(new CompoundName("d")), delta); - assertEquals(7.3, r.properties().getDouble(new CompoundName("d"),3.4d), delta); - assertEquals(3.4, r.properties().getDouble(new CompoundName("f"),3.4d), delta); + assertEquals(7.3, r.properties().getDouble(new CompoundName("d"), 3.4d), delta); + assertEquals(3.4, r.properties().getDouble(new CompoundName("f"), 3.4d), delta); assertNull(r.properties().getDouble("f")); - r.properties().set("o",true); + r.properties().set("o", true); assertEquals(true, r.properties().getBoolean("o")); - assertEquals(true, r.properties().getBoolean("o",true)); - assertEquals(true, r.properties().getBoolean("g",true)); + assertEquals(true, r.properties().getBoolean("o", true)); + assertEquals(true, r.properties().getBoolean("g", true)); assertEquals(false, r.properties().getBoolean("g")); assertEquals(true, r.properties().getBoolean(new CompoundName("o"))); - assertEquals(true, r.properties().getBoolean(new CompoundName("o"),true)); - assertEquals(true, r.properties().getBoolean(new CompoundName("g"),true)); + assertEquals(true, r.properties().getBoolean(new CompoundName("o"), true)); + assertEquals(true, r.properties().getBoolean(new CompoundName("g"), true)); assertEquals(false, r.properties().getBoolean("g")); r.properties().set(new CompoundName("x.y"), "x1.y1"); @@ -99,20 +99,20 @@ public class RequestTestCase { } @Test - public void testErrorMessages() { + void testErrorMessages() { Request r = new Request(); r.errors().add(new ErrorMessage("foo")); r.errors().add(new ErrorMessage("bar")); - assertEquals(2,r.errors().size()); + assertEquals(2, r.errors().size()); assertEquals("foo", r.errors().get(0).getMessage()); assertEquals("bar", r.errors().get(1).getMessage()); } @Test - public void testCloning() { + void testCloning() { Request request = new Request(); - request.properties().set("a","a1"); - request.properties().set("b","b1"); + request.properties().set("a", "a1"); + request.properties().set("b", "b1"); request.errors().add(new ErrorMessage("foo")); request.errors().add(new ErrorMessage("bar")); Request rcloned = request.clone(); @@ -125,17 +125,17 @@ public class RequestTestCase { assertEquals("a1", rcloned.properties().get("a")); assertEquals("b1", request.properties().get("b")); assertEquals("b1", rcloned.properties().get("b")); - assertEquals(null, request.properties().get("c")); + assertNull(request.properties().get("c")); assertEquals("c1", rcloned.properties().get("c")); assertEquals("d1", request.properties().get("d")); - assertEquals(null, rcloned.properties().get("d")); + assertNull(rcloned.properties().get("d")); assertEquals(3, request.errors().size()); assertEquals(1, rcloned.errors().size()); - assertEquals("foo",request.errors().get(0).getMessage()); - assertEquals("bar",request.errors().get(1).getMessage()); - assertEquals("boz",request.errors().get(2).getMessage()); - assertEquals("baz",rcloned.errors().get(0).getMessage()); + assertEquals("foo", request.errors().get(0).getMessage()); + assertEquals("bar", request.errors().get(1).getMessage()); + assertEquals("boz", request.errors().get(2).getMessage()); + assertEquals("baz", rcloned.errors().get(0).getMessage()); } } diff --git a/container-core/src/test/java/com/yahoo/processing/test/DocumentationTestCase.java b/container-core/src/test/java/com/yahoo/processing/test/DocumentationTestCase.java index 2028d39f973..8716b858696 100644 --- a/container-core/src/test/java/com/yahoo/processing/test/DocumentationTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/test/DocumentationTestCase.java @@ -1,11 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.processing.test; -import static org.junit.Assert.*; - -import org.junit.Test; - +import org.junit.jupiter.api.Test; import com.yahoo.component.chain.Chain; + +import static org.junit.jupiter.api.Assertions.assertEquals; import com.yahoo.processing.Processor; import com.yahoo.processing.Request; import com.yahoo.processing.Response; @@ -24,7 +23,7 @@ public class DocumentationTestCase { @SuppressWarnings("unchecked") @Test - public final void test() { + final void test() { Processor p = new ExampleProcessor(); Chain<Processor> basic = new Chain<>(p); Processor initiator = new AsyncDataProcessingInitiator(basic); diff --git a/container-core/src/test/java/com/yahoo/processing/test/ProcessingTestCase.java b/container-core/src/test/java/com/yahoo/processing/test/ProcessingTestCase.java index 3f11663a1d7..da1b406927f 100644 --- a/container-core/src/test/java/com/yahoo/processing/test/ProcessingTestCase.java +++ b/container-core/src/test/java/com/yahoo/processing/test/ProcessingTestCase.java @@ -6,10 +6,10 @@ import com.yahoo.processing.Processor; import com.yahoo.processing.Request; import com.yahoo.processing.Response; import com.yahoo.processing.execution.Execution; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.yahoo.processing.test.ProcessorLibrary.*; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests the basic of the processing framework @@ -18,43 +18,43 @@ public class ProcessingTestCase { /** Execute three simple processors doing some phony processing */ @Test - public void testChainedProcessing1() { + void testChainedProcessing1() { // Create a chain - Chain<Processor> chain=new Chain<>(new CombineData(),new Get6DataItems(), new DataSource()); + Chain<Processor> chain = new Chain<>(new CombineData(), new Get6DataItems(), new DataSource()); // Execute it - Request request=new Request(); - request.properties().set("appendage",1); - Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + request.properties().set("appendage", 1); + Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); // Verify the result - assertEquals(6-1,response.data().asList().size()); - assertEquals("first.2, third.2",response.data().get(0).toString()); - assertEquals("second.2",response.data().get(1).toString()); - assertEquals("first.3",response.data().get(2).toString()); - assertEquals("second.3",response.data().get(3).toString()); - assertEquals("third.3",response.data().get(4).toString()); + assertEquals(6 - 1, response.data().asList().size()); + assertEquals("first.2, third.2", response.data().get(0).toString()); + assertEquals("second.2", response.data().get(1).toString()); + assertEquals("first.3", response.data().get(2).toString()); + assertEquals("second.3", response.data().get(3).toString()); + assertEquals("third.3", response.data().get(4).toString()); } /** Execute the same processors in a different order */ @Test - public void testChainedProcessing2() { + void testChainedProcessing2() { // Create a chain - Chain<Processor> chain=new Chain<>(new Get6DataItems(),new CombineData(), new DataSource()); + Chain<Processor> chain = new Chain<>(new Get6DataItems(), new CombineData(), new DataSource()); // Execute it - Request request=new Request(); - request.properties().set("appendage",1); - Response response=Execution.createRoot(chain,0,Execution.Environment.createEmpty()).process(request); + Request request = new Request(); + request.properties().set("appendage", 1); + Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request); // Check the result - assertEquals(6,response.data().asList().size()); - assertEquals("first.2, third.2",response.data().get(0).toString()); - assertEquals("second.2",response.data().get(1).toString()); - assertEquals("first.4, third.4",response.data().get(2).toString()); - assertEquals("second.4",response.data().get(3).toString()); - assertEquals("first.6, third.6",response.data().get(4).toString()); - assertEquals("second.6",response.data().get(5).toString()); + assertEquals(6, response.data().asList().size()); + assertEquals("first.2, third.2", response.data().get(0).toString()); + assertEquals("second.2", response.data().get(1).toString()); + assertEquals("first.4, third.4", response.data().get(2).toString()); + assertEquals("second.4", response.data().get(3).toString()); + assertEquals("first.6, third.6", response.data().get(4).toString()); + assertEquals("second.6", response.data().get(5).toString()); } } |