55import java .time .Instant ;
66import java .time .ZoneId ;
77import java .time .ZonedDateTime ;
8- import java .util .Iterator ;
98import java .util .Optional ;
109import java .util .UUID ;
1110
@@ -126,30 +125,28 @@ void testByteArray() {
126125 // Starts an embedded in memory instance
127126 surreal .connect ("memory" ).useNs ("test_ns" ).useDb ("test_db" );
128127
129- // Test 1: Create a new record with byte[] data from raw bytes
128+ // Test 1: Create a new record with byte[] data from raw bytes (use RecordId for deterministic selection)
130129 final ByteData byteData = new ByteData ();
131130 byteData .data = new byte []{0x01 , 0x02 , 0x03 , 0x04 , 0x05 };
132- // We ingest the record
133- final ByteData created = surreal .create (ByteData .class , "bytedata" , byteData ). get ( 0 );
131+ final RecordId recordIdBytes = new RecordId ( "bytedata" , "bytedata" );
132+ final ByteData created = surreal .create (ByteData .class , recordIdBytes , byteData );
134133 // We check that the records are matching
135134 assertEquals (created , byteData );
136135
137- // Test 2: Create a new record with byte[] data converted from string
136+ // Test 2: Create a new record with byte[] data converted from string (use RecordId for deterministic selection)
138137 final ByteData byteDataFromString = new ByteData ();
139138 final String testString = "Hello" ;
140139 byteDataFromString .data = testString .getBytes ();
141- // We ingest the record
142- final ByteData createdFromString = surreal .create (ByteData .class , "bytedata:string" , byteDataFromString )
143- .get (0 );
140+ final RecordId recordIdString = new RecordId ("bytedata" , "string" );
141+ final ByteData createdFromString = surreal .create (ByteData .class , recordIdString , byteDataFromString );
144142 // We check that the records are matching
145143 assertEquals (createdFromString , byteDataFromString );
146144 // Verify we can convert the bytes back to string
147145 final String retrievedString = new String (createdFromString .data );
148146 assertEquals (retrievedString , testString );
149147
150- // Test 3: Select from database and verify byte[] is properly handled
151- final Iterator <ByteData > selectedRecords = surreal .select (ByteData .class , "bytedata" );
152- final ByteData selectedRecord = selectedRecords .next ();
148+ // Test 3: Select from database by record id and verify byte[] is properly handled
149+ final ByteData selectedRecord = surreal .select (ByteData .class , recordIdBytes ).orElseThrow ();
153150 // Compare the byte[] data content
154151 assertEquals (selectedRecord .data .length , byteData .data .length );
155152 for (int i = 0 ; i < selectedRecord .data .length ; i ++) {
@@ -160,10 +157,9 @@ void testByteArray() {
160157 assertEquals (selectedRecord .data [0 ], 0x01 );
161158 assertEquals (selectedRecord .data [4 ], 0x05 );
162159
163- // Test 4: Select the string-converted record and verify conversion back to
160+ // Test 4: Select the string-converted record by record id and verify conversion back to
164161 // string
165- final Iterator <ByteData > selectedStringRecords = surreal .select (ByteData .class , "bytedata:string" );
166- final ByteData selectedStringRecord = selectedStringRecords .next ();
162+ final ByteData selectedStringRecord = surreal .select (ByteData .class , recordIdString ).orElseThrow ();
167163 // Compare the byte[] data content
168164 assertEquals (selectedStringRecord .data .length , byteDataFromString .data .length );
169165 for (int i = 0 ; i < selectedStringRecord .data .length ; i ++) {
0 commit comments