|
22 | 22 | import java.net.URISyntaxException; |
23 | 23 | import java.security.InvalidKeyException; |
24 | 24 | import java.util.*; |
| 25 | +import java.util.concurrent.Executors; |
| 26 | +import java.util.concurrent.ThreadPoolExecutor; |
| 27 | +import java.util.concurrent.TimeUnit; |
| 28 | +import java.util.concurrent.atomic.AtomicInteger; |
| 29 | +import javax.xml.parsers.SAXParser; |
25 | 30 |
|
26 | 31 | import com.microsoft.azure.storage.*; |
| 32 | +import com.microsoft.azure.storage.core.Utility; |
27 | 33 | import org.junit.After; |
28 | 34 | import org.junit.Before; |
29 | 35 | import org.junit.Test; |
@@ -541,6 +547,49 @@ public void testCloudBlobContainerListBlobs() throws StorageException, IOExcepti |
541 | 547 | assertTrue(blobNames.size() == 0); |
542 | 548 | } |
543 | 549 |
|
| 550 | + @Test |
| 551 | + @Category({DevFabricTests.class, DevStoreTests.class}) |
| 552 | + public void testSAXParserConcurrency() throws Exception { |
| 553 | + final int totalCount = 200000; |
| 554 | + final int numThreads = 200; |
| 555 | + final AtomicInteger currentCount = new AtomicInteger(0); |
| 556 | + final AtomicInteger pending = new AtomicInteger(0); |
| 557 | + final AtomicInteger failureCount = new AtomicInteger(0); |
| 558 | + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(numThreads); |
| 559 | + |
| 560 | + do { |
| 561 | + final int count = currentCount.incrementAndGet(); |
| 562 | + pending.incrementAndGet(); |
| 563 | + executor.execute(new Runnable() { |
| 564 | + @Override |
| 565 | + public void run() { |
| 566 | + pending.decrementAndGet(); |
| 567 | + if (count > totalCount) { |
| 568 | + return; |
| 569 | + } |
| 570 | + try { |
| 571 | + SAXParser parser = Utility.getSAXParser(); |
| 572 | + if (!parser.isNamespaceAware()) { |
| 573 | + failureCount.incrementAndGet(); |
| 574 | + } |
| 575 | + assertEquals(true, parser.isNamespaceAware()); |
| 576 | + } catch (Exception e) { |
| 577 | + fail(e.toString()); |
| 578 | + } |
| 579 | + } |
| 580 | + }); |
| 581 | + |
| 582 | + assertEquals(0, failureCount.get()); |
| 583 | + |
| 584 | + while (pending.get() > numThreads * 2) { |
| 585 | + Thread.sleep(10); |
| 586 | + } |
| 587 | + } while (currentCount.get() < totalCount); |
| 588 | + executor.shutdown(); |
| 589 | + executor.awaitTermination(1, TimeUnit.MINUTES); |
| 590 | + executor.shutdownNow(); |
| 591 | + } |
| 592 | + |
544 | 593 | /** |
545 | 594 | * List the blobs in a container with a prefix |
546 | 595 | * |
|
0 commit comments