@@ -267,13 +267,14 @@ public void testGetIntoBufferMethods() {
267267 @ Test
268268 public void testConcurrentAdd () throws Exception {
269269 try (Index index = new Index .Config ().metric ("cos" ).dimensions (4 ).build ()) {
270- index .reserve (1000 );
270+ final int threadsCount = 10 ;
271+ index .reserve (1000 , threadsCount );
271272
272- ExecutorService executor = Executors .newFixedThreadPool (10 );
273+ ExecutorService executor = Executors .newFixedThreadPool (threadsCount );
273274 @ SuppressWarnings ("unchecked" )
274- CompletableFuture <Void >[] futures = new CompletableFuture [10 ];
275+ CompletableFuture <Void >[] futures = new CompletableFuture [threadsCount ];
275276
276- for (int t = 0 ; t < 10 ; t ++) {
277+ for (int t = 0 ; t < threadsCount ; t ++) {
277278 final int threadId = t ;
278279 futures [t ]
279280 = CompletableFuture .runAsync (
@@ -290,25 +291,26 @@ public void testConcurrentAdd() throws Exception {
290291 CompletableFuture .allOf (futures ).get (10 , TimeUnit .SECONDS );
291292 executor .shutdown ();
292293
293- assertEquals (500 , index .size ());
294+ assertEquals (50L * threadsCount , index .size ());
294295 }
295296 }
296297
297298 @ Test
298299 public void testConcurrentSearch () throws Exception {
299300 try (Index index = new Index .Config ().metric ("cos" ).dimensions (4 ).build ()) {
300- index .reserve (100 );
301+ final int threadsCount = 5 ;
302+ index .reserve (100 , threadsCount );
301303
302304 // Add some vectors first
303305 for (int i = 0 ; i < 100 ; i ++) {
304306 index .add (i , randomVector (4 ));
305307 }
306308
307- ExecutorService executor = Executors .newFixedThreadPool (5 );
309+ ExecutorService executor = Executors .newFixedThreadPool (threadsCount );
308310 @ SuppressWarnings ("unchecked" )
309- CompletableFuture <long []>[] futures = new CompletableFuture [5 ];
311+ CompletableFuture <long []>[] futures = new CompletableFuture [threadsCount ];
310312
311- for (int t = 0 ; t < 5 ; t ++) {
313+ for (int t = 0 ; t < threadsCount ; t ++) {
312314 futures [t ]
313315 = CompletableFuture .supplyAsync (
314316 () -> {
@@ -328,56 +330,6 @@ public void testConcurrentSearch() throws Exception {
328330 }
329331 }
330332
331- @ Test
332- public void testMixedConcurrency () throws Exception {
333- try (Index index = new Index .Config ().metric ("cos" ).dimensions (3 ).build ()) {
334- index .reserve (200 );
335-
336- ExecutorService executor = Executors .newFixedThreadPool (8 );
337- @ SuppressWarnings ("unchecked" )
338- CompletableFuture <Void >[] addFutures = new CompletableFuture [4 ];
339- @ SuppressWarnings ("unchecked" )
340- CompletableFuture <Void >[] searchFutures = new CompletableFuture [4 ];
341-
342- // Add operations
343- for (int t = 0 ; t < 4 ; t ++) {
344- final int threadId = t ;
345- addFutures [t ]
346- = CompletableFuture .runAsync (
347- () -> {
348- for (int i = 0 ; i < 30 ; i ++) {
349- long key = threadId * 30L + i ;
350- index .add (key , randomVector (3 ));
351- }
352- },
353- executor );
354- }
355-
356- // Wait for some adds to complete, then start searches
357- Thread .sleep (100 );
358-
359- // Search operations
360- for (int t = 0 ; t < 4 ; t ++) {
361- searchFutures [t ]
362- = CompletableFuture .runAsync (
363- () -> {
364- for (int i = 0 ; i < 10 ; i ++) {
365- float [] queryVector = randomVector (3 );
366- long [] results = index .search (queryVector , 5 );
367- assertTrue (results .length >= 0 );
368- }
369- },
370- executor );
371- }
372-
373- CompletableFuture .allOf (addFutures ).get (15 , TimeUnit .SECONDS );
374- CompletableFuture .allOf (searchFutures ).get (15 , TimeUnit .SECONDS );
375- executor .shutdown ();
376-
377- assertEquals (120 , index .size ());
378- }
379- }
380-
381333 @ Test
382334 public void testBatchAdd () {
383335 try (Index index = new Index .Config ().metric ("cos" ).dimensions (2 ).build ()) {
@@ -751,30 +703,30 @@ public void testPlatformCapabilities() {
751703 String [] available = Index .hardwareAccelerationAvailable ();
752704 assertNotEquals ("Available capabilities should not be null" , null , available );
753705 assertTrue ("Platform should have at least serial capability" , available .length > 0 );
754-
706+
755707 // Test compile-time capabilities
756708 String [] compiled = Index .hardwareAccelerationCompiled ();
757709 assertNotEquals ("Compiled capabilities should not be null" , null , compiled );
758710 assertTrue ("Should have at least serial compiled" , compiled .length > 0 );
759-
711+
760712 // Should always include serial as baseline in both
761713 boolean hasAvailableSerial = false ;
762714 boolean hasCompiledSerial = false ;
763-
715+
764716 for (String cap : available ) {
765717 if ("serial" .equals (cap )) {
766718 hasAvailableSerial = true ;
767719 break ;
768720 }
769721 }
770-
722+
771723 for (String cap : compiled ) {
772724 if ("serial" .equals (cap )) {
773725 hasCompiledSerial = true ;
774726 break ;
775727 }
776728 }
777-
729+
778730 assertTrue ("Platform should always support serial capability" , hasAvailableSerial );
779731 assertTrue ("Serial should always be compiled" , hasCompiledSerial );
780732
0 commit comments