@Test public void testIncrements() throws InterruptedException { final IdSourceKey generatorKey = buildIdGeneratorKey( ThreadSafetyEntity.class, THREAD_SAFETY_SEQUENCE ); final NextValueRequest nextValueRequest = new NextValueRequest( generatorKey, THREAD_SAFETY_INCREMENT, THREAD_SAFETY_FIRST_VALUE ); IncrementJob[] runJobs = runJobs( nextValueRequest ); // Verify we got unique results: int[] allGeneratedValues = new int[INCREASES_PER_TASK * NUMBER_OF_TASKS]; int i = 0; for ( IncrementJob job : runJobs ) { int[] generatedValuesPerJob = job.retrieveAllGeneratedValues(); for ( int generatedValue : generatedValuesPerJob ) { allGeneratedValues[i++] = generatedValue; } } Arrays.sort( allGeneratedValues ); int expectedValue = THREAD_SAFETY_FIRST_VALUE; for ( int k = 0; k < allGeneratedValues.length; k++ ) { assertThat( allGeneratedValues[k] ).as( "Unexpected value generated, index: " + k ).isEqualTo( expectedValue ); expectedValue += THREAD_SAFETY_INCREMENT; } }
@Test public void testIncrements() throws InterruptedException { final IdSourceKey generatorKey = buildIdGeneratorKey( ThreadSafetyEntity.class, THREAD_SAFETY_SEQUENCE ); final NextValueRequest nextValueRequest = new NextValueRequest( generatorKey, THREAD_SAFETY_INCREMENT, THREAD_SAFETY_FIRST_VALUE ); IncrementJob[] runJobs = runJobs( nextValueRequest ); // Verify we got unique results: int[] allGeneratedValues = new int[INCREASES_PER_TASK * NUMBER_OF_TASKS]; int i = 0; for ( IncrementJob job : runJobs ) { int[] generatedValuesPerJob = job.retrieveAllGeneratedValues(); for ( int generatedValue : generatedValuesPerJob ) { allGeneratedValues[i++] = generatedValue; } } Arrays.sort( allGeneratedValues ); int expectedValue = THREAD_SAFETY_FIRST_VALUE; for ( int generatedValue : allGeneratedValues ) { assertThat( generatedValue ).as( "Unexpected value generated" ).isEqualTo( expectedValue ); expectedValue += THREAD_SAFETY_INCREMENT; } }
private static void verifyIssue(TestIssue expected, Issue actual, File file) { if (line(actual) > expected.line()) { fail("Missing issue at line " + expected.line() + " in file " + file.getAbsolutePath()); } if (line(actual) < expected.line()) { fail("Unexpected issue at line " + line(actual) + ": \"" + message(actual) + "\"" + " in file " + file.getAbsolutePath()); } if (expected.message() != null) { assertThat(message(actual)).as("Bad message at line " + expected.line()).isEqualTo(expected.message()); } if (expected.effortToFix() != null) { assertThat(actual.cost()).as("Bad effortToFix at line " + expected.line()).isEqualTo(expected.effortToFix()); } if (expected.startColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().startLineOffset() + 1).as("Bad start column at line " + expected.line()).isEqualTo(expected.startColumn()); } if (expected.endColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLineOffset() + 1).as("Bad end column at line " + expected.line()).isEqualTo(expected.endColumn()); } if (expected.endLine() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLine()).as("Bad end line at line " + expected.line()).isEqualTo(expected.endLine()); } if (expected.secondaryLines() != null) { assertThat(secondary(actual)).as("Bad secondary locations at line " + expected.line()).isEqualTo(expected.secondaryLines()); } }
private static void verifyIssue(TestIssue expected, Issue actual, File file) { if (line(actual) > expected.line()) { fail("Missing issue at line " + expected.line() + " in file " + file.getAbsolutePath()); } if (line(actual) < expected.line()) { fail("Unexpected issue at line " + line(actual) + ": \"" + message(actual) + "\"" + " in file " + file.getAbsolutePath()); } if (expected.message() != null) { assertThat(message(actual)).as("Bad message at line " + expected.line()).isEqualTo(expected.message()); } if (expected.effortToFix() != null) { assertThat(actual.cost()).as("Bad effortToFix at line " + expected.line()).isEqualTo(expected.effortToFix()); } if (expected.startColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().startLineOffset() + 1).as("Bad start column at line " + expected.line()).isEqualTo(expected.startColumn()); } if (expected.endColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLineOffset() + 1).as("Bad end column at line " + expected.line()).isEqualTo(expected.endColumn()); } if (expected.endLine() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLine()).as("Bad end line at line " + expected.line()).isEqualTo(expected.endLine()); } if (expected.secondaryLines() != null) { assertThat(secondary(actual)).as("Bad secondary locations at line " + expected.line()).isEqualTo(expected.secondaryLines()); } }