Author: veithen
Date: Sat May 9 23:09:40 2015
New Revision: 1678531
URL: http://svn.apache.org/r1678531
Log:
Fix a bug in the state tracking of the WritableBlob implementations.
Added:
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/TestReadFromCommitted.java
(with props)
Modified:
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestSuiteBuilder.java
Modified:
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java?rev=1678531&r1=1678530&r2=1678531&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
(original)
+++
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
Sat May 9 23:09:40 2015
@@ -182,6 +182,9 @@ public class MemoryBlob implements Writa
}
public long readFrom(InputStream in, long length, boolean commit) throws
StreamCopyException {
+ if (committed) {
+ throw new IllegalStateException();
+ }
if (data == null) {
init();
}
Modified:
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java?rev=1678531&r1=1678530&r2=1678531&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
(original)
+++
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
Sat May 9 23:09:40 2015
@@ -312,6 +312,9 @@ public class OverflowBlob implements Wri
}
public long readFrom(InputStream in, long length, boolean commit) throws
StreamCopyException {
+ if (state == STATE_COMMITTED) {
+ throw new IllegalStateException();
+ }
// TODO: this will not work if the blob is in state UNCOMMITTED and we
have already switched to a temporary file
long read = 0;
long toRead = length == -1 ? Long.MAX_VALUE : length;
Added:
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/TestReadFromCommitted.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/TestReadFromCommitted.java?rev=1678531&view=auto
==============================================================================
---
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/TestReadFromCommitted.java
(added)
+++
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/TestReadFromCommitted.java
Sat May 9 23:09:40 2015
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.util.blob;
+
+import org.apache.commons.io.input.NullInputStream;
+
+public class TestReadFromCommitted extends WritableBlobTestCase {
+ private final Boolean commit;
+
+ public TestReadFromCommitted(WritableBlobFactory factory, Boolean commit) {
+ super(factory);
+ this.commit = commit;
+ addTestParameter("commit", String.valueOf(commit));
+ }
+
+ @Override
+ protected void runTest(WritableBlob blob) throws Throwable {
+ blob.getOutputStream().close();
+ try {
+ if (commit == null) {
+ blob.readFrom(new NullInputStream(0), -1);
+ } else {
+ blob.readFrom(new NullInputStream(0), -1, commit);
+ }
+ fail("Expected IllegalStateException");
+ } catch (IllegalStateException ex) {
+ // Expected
+ }
+ }
+}
Propchange:
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/TestReadFromCommitted.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestSuiteBuilder.java?rev=1678531&r1=1678530&r2=1678531&view=diff
==============================================================================
---
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestSuiteBuilder.java
(original)
+++
webservices/axiom/trunk/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestSuiteBuilder.java
Sat May 9 23:09:40 2015
@@ -36,6 +36,9 @@ public class WritableBlobTestSuiteBuilde
addTest(new TestMarkReset(factory));
addTest(new TestReadFrom(factory, 10000));
addTest(new TestReadFrom(factory, 100000));
+ addTest(new TestReadFromCommitted(factory, null));
+ addTest(new TestReadFromCommitted(factory, Boolean.FALSE));
+ addTest(new TestReadFromCommitted(factory, Boolean.TRUE));
addTest(new TestRandomReadWrite(factory, 10000));
addTest(new TestRandomReadWrite(factory, 100000));
};