From 60b1f8f322e96258f2068f792f2441c517720b52 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Fri, 18 Aug 2017 09:29:57 -0700 Subject: [PATCH 1/5] Updating contributing doc to include intellij --- CONTRIBUTING.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8796767aca7c5..f1ba760c79aa8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,16 +1,20 @@ If you intend to contribute to the project, please make sure you've followed the instructions provided in the [Azure Projects Contribution Guidelines](http://azure.github.io/guidelines/). ## Project Setup -The Azure Storage development team uses Eclipse so instructions will be tailored to that preference. However, any preferred IDE or other toolset should be usable. +The Azure Storage development team uses Intellij. However, any preferred IDE or other toolset should be usable. ### Install * Java SE 6+ -* [Eclipse](https://eclipse.org/downloads/) -* [Maven plugin for Eclipse](http://www.eclipse.org/m2e/index.html). Some Eclipse packages (ex Eclipse IDE for Java Developers) may come with this plugin already installed. * [Maven](https://maven.apache.org/install.html) * Clone the source code from GitHub -### Open Solution -Open the project from Eclipse using File->Import->Maven->Existing Maven Projects and navigating to the azure-storage-java folder. Select the listed pom. This imports the source and the test files and downloads the required dependencies via Maven. If you'd like to import the samples, follow the same procedure but navigate to the azure-storage-java\microsoft-azure-storage-samples folder and select that pom. Both projects can be opened at the same time and will be shown in the Package Explorer. +#### IntelliJ Installation +* [IntelliJ](https://www.jetbrains.com/idea/download) +* [Importing project from Maven for IntelliJ](https://www.jetbrains.com/help/idea//2017.1/importing-project-from-maven-model.html) + +#### Eclipse Installation +* [Eclipse](https://eclipse.org/downloads/) +* [Maven plugin for Eclipse](http://www.eclipse.org/m2e/index.html). Some Eclipse packages (ex Eclipse IDE for Java Developers) may come with this plugin already installed. +* Open the project from Eclipse using File->Import->Maven->Existing Maven Projects and navigating to the azure-storage-java folder. Select the listed pom. This imports the source and the test files and downloads the required dependencies via Maven. If you'd like to import the samples, follow the same procedure but navigate to the azure-storage-java\microsoft-azure-storage-samples folder and select that pom. Both projects can be opened at the same time and will be shown in the Package Explorer. ## Tests @@ -38,7 +42,7 @@ The following are the minimum requirements for any pull request that must be met * Thoroughly test your feature ### Branching Policy -Changes should be based on the **dev** branch, not master as master is considered publicly released code. If after discussion with us breaking changes are considered for the library, we will create a **dev_breaking** branch based on dev which can be used to store these changes until the next breaking release. Each breaking change should be recorded in [BreakingChanges.md](BreakingChanges.md). +Changes should be based on the **dev** branch for non-breaking changes and **dev_breaking** for breaking changes. Do not submit pull requests against master as master is considered publicly released code. Each breaking change should be recorded in [BreakingChanges.md](BreakingChanges.md). ### Adding Features for Java 6+ We strive to release each new feature in a backward compatible manner. Therefore, we ask that all contributions be written to work in Java 6, 7 and 8. From 640f6824209a20c44d4403e51de94f6cadfa3969 Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Tue, 29 Aug 2017 09:07:02 -0700 Subject: [PATCH 2/5] Fix event firing test and improve perf parsing premium page blob tiers --- .../azure/storage/EventFiringTests.java | 58 ++++++++++--------- .../storage/blob/PremiumPageBlobTier.java | 21 ++++--- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/EventFiringTests.java b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/EventFiringTests.java index 6ee2236d86e86..4f6dc4c1515ab 100644 --- a/microsoft-azure-storage-test/src/com/microsoft/azure/storage/EventFiringTests.java +++ b/microsoft-azure-storage-test/src/com/microsoft/azure/storage/EventFiringTests.java @@ -121,39 +121,45 @@ public void eventOccurred(ErrorReceivingResponseEvent eventArg) { } }); - OperationContext.getGlobalErrorReceivingResponseEventHandler().addListener(new StorageEvent() { + try { + OperationContext.getGlobalErrorReceivingResponseEventHandler().addListener(new StorageEvent() { - @Override - public void eventOccurred(ErrorReceivingResponseEvent eventArg) { - fail("This event should not trigger"); - } - }); + @Override + public void eventOccurred(ErrorReceivingResponseEvent eventArg) { + fail("This event should not trigger"); + } + }); - assertEquals(0, callList.size()); - assertEquals(0, globalCallList.size()); + assertEquals(0, callList.size()); + assertEquals(0, globalCallList.size()); - CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); - CloudBlobContainer container = blobClient.getContainerReference("container1"); + CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); + CloudBlobContainer container = blobClient.getContainerReference("container1"); - // make sure both update - container.exists(null, null, eventContext); - assertEquals(1, callList.size()); - assertEquals(1, globalCallList.size()); + // make sure both update + container.exists(null, null, eventContext); + assertEquals(1, callList.size()); + assertEquals(1, globalCallList.size()); - // make sure only global updates - container.exists(); - assertEquals(1, callList.size()); - assertEquals(2, globalCallList.size()); + // make sure only global updates + container.exists(); + assertEquals(1, callList.size()); + assertEquals(2, globalCallList.size()); - OperationContext - .setGlobalResponseReceivedEventHandler(new StorageEventMultiCaster>()); - eventContext - .setResponseReceivedEventHandler(new StorageEventMultiCaster>()); + OperationContext + .setGlobalResponseReceivedEventHandler(new StorageEventMultiCaster>()); + eventContext + .setResponseReceivedEventHandler(new StorageEventMultiCaster>()); - // make sure neither update - container.exists(null, null, eventContext); - assertEquals(1, callList.size()); - assertEquals(2, globalCallList.size()); + // make sure neither update + container.exists(null, null, eventContext); + assertEquals(1, callList.size()); + assertEquals(2, globalCallList.size()); + } + finally { + // reset event handler to prevent future tests from failing + OperationContext.setGlobalErrorReceivingResponseEventHandler(new StorageEventMultiCaster>()); + } } @Test diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/PremiumPageBlobTier.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/PremiumPageBlobTier.java index 590a66c334f77..ffcc51670a58f 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/PremiumPageBlobTier.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/PremiumPageBlobTier.java @@ -77,32 +77,35 @@ public enum PremiumPageBlobTier { * * @return A PremiumPageBlobTier value that represents the premium page blob tier. */ - protected static PremiumPageBlobTier parse(final String premiumBlobTierString) { + protected static PremiumPageBlobTier parse(String premiumBlobTierString) { + if (Utility.isNullOrEmpty(premiumBlobTierString)) { return UNKNOWN; } - else if ("p4".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + + premiumBlobTierString = premiumBlobTierString.toLowerCase(Locale.US); + if ("p4".equals(premiumBlobTierString)) { return P4; } - else if ("p6".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p6".equals(premiumBlobTierString)) { return P6; } - else if ("p10".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p10".equals(premiumBlobTierString)) { return P10; } - else if ("p20".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p20".equals(premiumBlobTierString)) { return P20; } - else if ("p30".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p30".equals(premiumBlobTierString)) { return P30; } - else if ("p40".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p40".equals(premiumBlobTierString)) { return P40; } - else if ("p50".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p50".equals(premiumBlobTierString)) { return P50; } - else if ("p60".equals(premiumBlobTierString.toLowerCase(Locale.US))) { + else if ("p60".equals(premiumBlobTierString)) { return P60; } else { From cac8f472cb7e71ee50fceba899e39f7cc3fc52e9 Mon Sep 17 00:00:00 2001 From: CodingCat Date: Mon, 4 Sep 2017 20:45:49 -0700 Subject: [PATCH 3/5] set thread pool as daemon --- .../blob/BlobOutputStreamInternal.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java index 44fde57d3f7a1..3f34049735052 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java @@ -27,13 +27,8 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; import com.microsoft.azure.storage.AccessCondition; import com.microsoft.azure.storage.Constants; @@ -51,6 +46,29 @@ */ final class BlobOutputStreamInternal extends BlobOutputStream { + private static class BlobOutputStreamThreadFactory implements ThreadFactory { + private final ThreadGroup group; + private final AtomicInteger threadNumber = new AtomicInteger(1); + private final String namePrefix; + + BlobOutputStreamThreadFactory() { + SecurityManager s = System.getSecurityManager(); + group = (s != null) ? s.getThreadGroup() : + Thread.currentThread().getThreadGroup(); + namePrefix = "azure-storage-bloboutputstream-thread-"; + } + + public Thread newThread(Runnable r) { + Thread t = new Thread(group, r, + namePrefix + threadNumber.getAndIncrement(), + 0); + t.setDaemon(false); + if (t.getPriority() != Thread.NORM_PRIORITY) + t.setPriority(Thread.NORM_PRIORITY); + return t; + } + } + /** * Holds the {@link AccessCondition} object that represents the access conditions for the blob. */ @@ -171,9 +189,10 @@ private BlobOutputStreamInternal(final CloudBlob parentBlob, final AccessConditi this.threadExecutor = new ThreadPoolExecutor( this.options.getConcurrentRequestCount(), this.options.getConcurrentRequestCount(), - 10, + 10, TimeUnit.SECONDS, - new LinkedBlockingQueue()); + new LinkedBlockingQueue(), + new BlobOutputStreamThreadFactory()); this.completionService = new ExecutorCompletionService(this.threadExecutor); } From 7e7f32961deb40ff0d0be842f737ba027e0c46e8 Mon Sep 17 00:00:00 2001 From: CodingCat Date: Mon, 4 Sep 2017 20:58:00 -0700 Subject: [PATCH 4/5] fix typo --- .../microsoft/azure/storage/blob/BlobOutputStreamInternal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java index 3f34049735052..0d3854373d764 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java @@ -62,7 +62,7 @@ public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); - t.setDaemon(false); + t.setDaemon(true); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t; From af86e4e2810e30aa8aa4d301843d03d5965c915a Mon Sep 17 00:00:00 2001 From: Josh Friedman Date: Wed, 6 Sep 2017 09:10:30 -0700 Subject: [PATCH 5/5] Set logging properties to null if service does not return them --- .../com/microsoft/azure/storage/ServicePropertiesHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java index 44ce349675219..ec370d5df2ef9 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/ServicePropertiesHandler.java @@ -58,7 +58,7 @@ public static ServiceProperties readServicePropertiesFromStream(final InputStrea IOException, ParserConfigurationException { SAXParser saxParser = Utility.getSAXParser(); ServicePropertiesHandler handler = new ServicePropertiesHandler(); - handler.props.setCors(null); + handler.props.setLogging(null); handler.props.setHourMetrics(null); handler.props.setMinuteMetrics(null); handler.props.setCors(null);