|
20 | 20 | import com.microsoft.azure.storage.TestRunners.DevFabricTests; |
21 | 21 | import com.microsoft.azure.storage.TestRunners.DevStoreTests; |
22 | 22 |
|
23 | | -import org.apache.http.protocol.HTTP; |
24 | 23 | import org.junit.Test; |
25 | 24 | import org.junit.experimental.categories.Category; |
26 | 25 |
|
27 | | -import java.io.ByteArrayInputStream; |
28 | | -import java.io.IOException; |
29 | 26 | import java.net.HttpURLConnection; |
30 | | -import java.net.SocketException; |
31 | 27 | import java.net.URISyntaxException; |
32 | 28 | import java.util.ArrayList; |
33 | 29 |
|
@@ -121,39 +117,46 @@ public void eventOccurred(ErrorReceivingResponseEvent eventArg) { |
121 | 117 | } |
122 | 118 | }); |
123 | 119 |
|
124 | | - OperationContext.getGlobalErrorReceivingResponseEventHandler().addListener(new StorageEvent<ErrorReceivingResponseEvent>() { |
| 120 | + StorageEvent<ErrorReceivingResponseEvent> globalResponseReceivedListener = new StorageEvent<ErrorReceivingResponseEvent>() { |
125 | 121 |
|
126 | 122 | @Override |
127 | 123 | public void eventOccurred(ErrorReceivingResponseEvent eventArg) { |
128 | 124 | fail("This event should not trigger"); |
129 | 125 | } |
130 | | - }); |
| 126 | + }; |
131 | 127 |
|
132 | | - assertEquals(0, callList.size()); |
133 | | - assertEquals(0, globalCallList.size()); |
| 128 | + try { |
| 129 | + OperationContext.getGlobalErrorReceivingResponseEventHandler().addListener(globalResponseReceivedListener); |
134 | 130 |
|
135 | | - CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); |
136 | | - CloudBlobContainer container = blobClient.getContainerReference("container1"); |
| 131 | + assertEquals(0, callList.size()); |
| 132 | + assertEquals(0, globalCallList.size()); |
137 | 133 |
|
138 | | - // make sure both update |
139 | | - container.exists(null, null, eventContext); |
140 | | - assertEquals(1, callList.size()); |
141 | | - assertEquals(1, globalCallList.size()); |
| 134 | + CloudBlobClient blobClient = TestHelper.createCloudBlobClient(); |
| 135 | + CloudBlobContainer container = blobClient.getContainerReference("container1"); |
142 | 136 |
|
143 | | - // make sure only global updates |
144 | | - container.exists(); |
145 | | - assertEquals(1, callList.size()); |
146 | | - assertEquals(2, globalCallList.size()); |
| 137 | + // make sure both update |
| 138 | + container.exists(null, null, eventContext); |
| 139 | + assertEquals(1, callList.size()); |
| 140 | + assertEquals(1, globalCallList.size()); |
147 | 141 |
|
148 | | - OperationContext |
149 | | - .setGlobalResponseReceivedEventHandler(new StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>>()); |
150 | | - eventContext |
151 | | - .setResponseReceivedEventHandler(new StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>>()); |
| 142 | + // make sure only global updates |
| 143 | + container.exists(); |
| 144 | + assertEquals(1, callList.size()); |
| 145 | + assertEquals(2, globalCallList.size()); |
152 | 146 |
|
153 | | - // make sure neither update |
154 | | - container.exists(null, null, eventContext); |
155 | | - assertEquals(1, callList.size()); |
156 | | - assertEquals(2, globalCallList.size()); |
| 147 | + OperationContext |
| 148 | + .setGlobalResponseReceivedEventHandler(new StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>>()); |
| 149 | + eventContext |
| 150 | + .setResponseReceivedEventHandler(new StorageEventMultiCaster<ResponseReceivedEvent, StorageEvent<ResponseReceivedEvent>>()); |
| 151 | + |
| 152 | + // make sure neither update |
| 153 | + container.exists(null, null, eventContext); |
| 154 | + assertEquals(1, callList.size()); |
| 155 | + assertEquals(2, globalCallList.size()); |
| 156 | + } |
| 157 | + finally { |
| 158 | + OperationContext.getGlobalErrorReceivingResponseEventHandler().removeListener(globalResponseReceivedListener); |
| 159 | + } |
157 | 160 | } |
158 | 161 |
|
159 | 162 | @Test |
|
0 commit comments