Skip to content

Commit 7d61e6d

Browse files
Merge branch 'real-logic:master' into master
2 parents dc9151c + 02b0c7a commit 7d61e6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+9465
-225
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
fail-fast: false
9090
matrix:
9191
language: [ 'csharp' ]
92-
dotnet: [ '3.1.x' ]
92+
dotnet: [ '8.0.x' ]
9393
env:
9494
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
9595
DOTNET_CLI_TELEMETRY_OPTOUT: 1

.github/workflows/slow.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Slow checks
2+
3+
on:
4+
workflow_dispatch:
5+
branches:
6+
- '**'
7+
schedule:
8+
- cron: '0 12 * * *'
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
GRADLE_OPTS: '-Dorg.gradle.daemon=false -Dorg.gradle.java.installations.auto-detect=false -Dorg.gradle.warning.mode=fail'
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
property-tests:
22+
name: Property tests
23+
runs-on: ubuntu-22.04
24+
strategy:
25+
matrix:
26+
java: [ '21' ]
27+
dotnet: [ '8.0.x' ]
28+
env:
29+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
30+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v3
34+
- name: Setup java
35+
uses: actions/setup-java@v3
36+
with:
37+
distribution: 'zulu'
38+
java-version: ${{ matrix.java }}
39+
- name: Setup BUILD_JAVA_HOME & BUILD_JAVA_VERSION
40+
run: |
41+
java -Xinternalversion
42+
echo "BUILD_JAVA_HOME=${JAVA_HOME}" >> $GITHUB_ENV
43+
echo "BUILD_JAVA_VERSION=${{ matrix.java }}" >> $GITHUB_ENV
44+
- name: Setup java 8 to run the Gradle script
45+
uses: actions/setup-java@v3
46+
with:
47+
distribution: 'zulu'
48+
java-version: 8
49+
- name: Setup dotnet
50+
uses: actions/setup-dotnet@v2
51+
with:
52+
dotnet-version: ${{ matrix.dotnet }}
53+
- name: Build .NET library
54+
run: ./csharp/build.sh
55+
- name: Run property tests
56+
run: ./gradlew propertyTest
57+
- name: Upload test results
58+
uses: actions/upload-artifact@v3
59+
if: success() || failure()
60+
with:
61+
name: property-tests
62+
path: sbe-tool/build/reports/tests/propertyTest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,7 @@ rust/Cargo.lock
119119
.DS_Store
120120
/sbe-tool/src/main/golang/uk_co_real_logic_sbe_ir_generated/
121121

122+
# JQwik
123+
*.jqwik-database
124+
122125
/generated/

build.gradle

Lines changed: 103 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ buildscript {
3131

3232
plugins {
3333
id 'java-library'
34+
id 'jvm-test-suite'
3435
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
3536
id 'com.github.ben-manes.versions' version '0.51.0'
3637
}
@@ -56,7 +57,9 @@ def toolchainLauncher = javaToolchains.launcherFor {
5657
def checkstyleVersion = '9.3'
5758
def hamcrestVersion = '2.2'
5859
def mockitoVersion = '4.11.0'
59-
def junitVersion = '5.10.2'
60+
def junitVersion = '5.10.3'
61+
def jqwikVersion = '1.9.0'
62+
def jsonVersion = '20240303'
6063
def jmhVersion = '1.37'
6164
def agronaVersion = '1.21.2'
6265
def agronaVersionRange = '[1.21.2,2.0[' // allow any release >= 1.21.2 and < 2.0.0
@@ -172,6 +175,7 @@ jar.enabled = false
172175

173176
subprojects {
174177
apply plugin: 'java-library'
178+
apply plugin: 'jvm-test-suite'
175179
apply plugin: 'checkstyle'
176180

177181
group = sbeGroup
@@ -224,22 +228,34 @@ subprojects {
224228
}
225229
}
226230

227-
test {
228-
useJUnitPlatform()
231+
testing {
232+
suites {
233+
test {
234+
useJUnitJupiter junitVersion
229235

230-
testLogging {
231-
for (def level : LogLevel.values())
232-
{
233-
def testLogging = get(level)
234-
testLogging.exceptionFormat = 'full'
235-
testLogging.events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
236-
}
237-
}
236+
targets {
237+
all {
238+
testTask.configure {
239+
useJUnitPlatform()
238240

239-
javaLauncher.set(toolchainLauncher)
241+
testLogging {
242+
for (def level : LogLevel.values())
243+
{
244+
def testLogging = get(level)
245+
testLogging.exceptionFormat = 'full'
246+
testLogging.events = ["FAILED", "STANDARD_OUT", "STANDARD_ERROR"]
247+
}
248+
}
249+
250+
javaLauncher.set(toolchainLauncher)
240251

241-
systemProperty 'sbe.enable.ir.precedence.checks', 'true'
242-
systemProperty 'sbe.enable.test.precedence.checks', 'true'
252+
systemProperty 'sbe.enable.ir.precedence.checks', 'true'
253+
systemProperty 'sbe.enable.test.precedence.checks', 'true'
254+
}
255+
}
256+
}
257+
}
258+
}
243259
}
244260
}
245261

@@ -256,11 +272,6 @@ project(':sbe-tool') {
256272
prefer(agronaVersion)
257273
}
258274
}
259-
testImplementation files('build/classes/java/generated')
260-
testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
261-
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
262-
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
263-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
264275
}
265276

266277
def generatedDir = 'build/generated-src'
@@ -277,11 +288,55 @@ project(':sbe-tool') {
277288

278289
compileGeneratedJava {
279290
dependsOn 'generateTestCodecs'
291+
dependsOn 'generateTestDtos'
280292
classpath += sourceSets.main.runtimeClasspath
281293
}
282294

283295
compileTestJava.dependsOn compileGeneratedJava
284296

297+
testing {
298+
suites {
299+
test {
300+
dependencies {
301+
implementation files('build/classes/java/generated')
302+
implementation "org.hamcrest:hamcrest:${hamcrestVersion}"
303+
implementation "org.mockito:mockito-core:${mockitoVersion}"
304+
implementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
305+
}
306+
}
307+
308+
propertyTest(JvmTestSuite) {
309+
// We should be able to use _only_ the JQwik engine, but this issue is outstanding:
310+
// https://github.com/gradle/gradle/issues/21299
311+
useJUnitJupiter junitVersion
312+
313+
dependencies {
314+
implementation project()
315+
implementation("net.jqwik:jqwik:${jqwikVersion}") {
316+
// Exclude JUnit 5 dependencies that are already provided due to useJUnitJupiter
317+
exclude group: 'org.junit.platform', module: 'junit-platform-commons'
318+
exclude group: 'org.junit.platform', module: 'junit-platform-engine'
319+
}
320+
implementation "org.json:json:${jsonVersion}"
321+
}
322+
323+
324+
targets {
325+
all {
326+
testTask.configure {
327+
minHeapSize = '2g'
328+
maxHeapSize = '2g'
329+
330+
javaLauncher.set(toolchainLauncher)
331+
332+
systemProperty 'sbe.dll', "${rootProject.projectDir}/csharp/sbe-dll/bin/Release/netstandard2.0/SBE.dll"
333+
}
334+
}
335+
}
336+
}
337+
}
338+
}
339+
285340
tasks.register('generateTestCodecs', JavaExec) {
286341
dependsOn 'compileJava'
287342
mainClass.set('uk.co.real_logic.sbe.SbeTool')
@@ -298,6 +353,21 @@ project(':sbe-tool') {
298353
'src/test/resources/field-order-check-schema.xml']
299354
}
300355

356+
tasks.register('generateTestDtos', JavaExec) {
357+
dependsOn 'compileJava'
358+
mainClass.set('uk.co.real_logic.sbe.SbeTool')
359+
classpath = sourceSets.main.runtimeClasspath
360+
systemProperties(
361+
'sbe.output.dir': generatedDir,
362+
'sbe.target.language': 'java',
363+
'sbe.validation.stop.on.error': 'true',
364+
'sbe.validation.xsd': validationXsdPath,
365+
'sbe.generate.precedence.checks': 'true',
366+
'sbe.java.precedence.checks.property.name': 'sbe.enable.test.precedence.checks',
367+
'sbe.java.generate.dtos': 'true')
368+
args = ['src/test/resources/example-extension-schema.xml']
369+
}
370+
301371
jar {
302372
manifest.attributes(
303373
'Specification-Title': 'Simple Binary Encoding',
@@ -755,7 +825,7 @@ tasks.register('generateCSharpCodecsWithXIncludes', JavaExec) {
755825
'sbe-samples/src/main/resources/example-extension-schema.xml']
756826
}
757827

758-
tasks.register('generateCSharpCodecsTests', JavaExec) {
828+
tasks.register('generateCSharpTestCodecs', JavaExec) {
759829
mainClass.set('uk.co.real_logic.sbe.SbeTool')
760830
classpath = project(':sbe-tool').sourceSets.main.runtimeClasspath
761831
systemProperties(
@@ -774,9 +844,21 @@ tasks.register('generateCSharpCodecsTests', JavaExec) {
774844
'sbe-benchmarks/src/main/resources/fix-message-samples.xml']
775845
}
776846

847+
tasks.register('generateCSharpTestDtos', JavaExec) {
848+
mainClass.set('uk.co.real_logic.sbe.SbeTool')
849+
classpath = project(':sbe-tool').sourceSets.main.runtimeClasspath
850+
systemProperties(
851+
'sbe.output.dir': 'csharp/sbe-generated',
852+
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.CSharpDtos',
853+
'sbe.xinclude.aware': 'true',
854+
'sbe.validation.xsd': validationXsdPath)
855+
args = ['sbe-samples/src/main/resources/example-extension-schema.xml']
856+
}
857+
777858
tasks.register('generateCSharpCodecs') {
778859
description = 'Generate csharp codecs'
779-
dependsOn 'generateCSharpCodecsTests',
860+
dependsOn 'generateCSharpTestCodecs',
861+
'generateCSharpTestDtos',
780862
'generateCSharpCodecsWithXIncludes'
781863
}
782864

config/checkstyle/suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<suppress files=".*generated-src.*" checks="."/>
77
<suppress files=".*generated.*" checks="."/>
88
<suppress files="[\\/]test[\\/]" checks="MissingJavadoc.*"/>
9+
<suppress files="[\\/]propertyTest[\\/]" checks="MissingJavadoc.*"/>
910
<suppress files="[\\/]sbe-benchmarks[\\/]" checks="MissingJavadoc.*"/>
1011
</suppressions>

csharp/sbe-dll/DirectBuffer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,21 +694,16 @@ public int SetBytes(int index, ReadOnlySpan<byte> src)
694694

695695
/// <summary>
696696
/// Writes a string into the underlying buffer, encoding using the provided <see cref="System.Text.Encoding"/>.
697-
/// If there is not enough room in the buffer for the bytes it will throw IndexOutOfRangeException.
698697
/// </summary>
699698
/// <param name="encoding">encoding to use to write the bytes from the string</param>
700699
/// <param name="src">source string</param>
701700
/// <param name="index">index in the underlying buffer to start writing bytes</param>
702701
/// <returns>count of bytes written</returns>
703702
public unsafe int SetBytesFromString(Encoding encoding, string src, int index)
704703
{
705-
int available = _capacity - index;
706704
int byteCount = encoding.GetByteCount(src);
707705

708-
if (byteCount > available)
709-
{
710-
ThrowHelper.ThrowIndexOutOfRangeException(_capacity);
711-
}
706+
CheckLimit(index + byteCount);
712707

713708
fixed (char* ptr = src)
714709
{

0 commit comments

Comments
 (0)