-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Heemin Kim <[email protected]>
- Loading branch information
Showing
6 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/org/opensearch/geospatial/exceptions/ConcurrentModificationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.geospatial.exceptions; | ||
|
||
import java.io.IOException; | ||
|
||
import org.opensearch.OpenSearchException; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.rest.RestStatus; | ||
|
||
/** | ||
* General ConcurrentModificationException corresponding to the {@link RestStatus#BAD_REQUEST} status code | ||
* | ||
* The exception is thrown when multiple mutation API is called for a same resource at the same time | ||
*/ | ||
public class ConcurrentModificationException extends OpenSearchException { | ||
|
||
public ConcurrentModificationException(String msg, Object... args) { | ||
super(msg, args); | ||
} | ||
|
||
public ConcurrentModificationException(String msg, Throwable cause, Object... args) { | ||
super(msg, cause, args); | ||
} | ||
|
||
public ConcurrentModificationException(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public final RestStatus status() { | ||
return RestStatus.BAD_REQUEST; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/org/opensearch/geospatial/exceptions/ConcurrentModificationExceptionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.geospatial.exceptions; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import org.opensearch.common.io.stream.BytesStreamInput; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.rest.RestStatus; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
public class ConcurrentModificationExceptionTests extends OpenSearchTestCase { | ||
public void testConstructor_whenCreated_thenSucceed() { | ||
ConcurrentModificationException exception = new ConcurrentModificationException("Resource is being modified by another processor"); | ||
assertEquals(RestStatus.BAD_REQUEST, exception.status()); | ||
} | ||
|
||
public void testConstructor_whenCreatedWithRootCause_thenSucceed() { | ||
ConcurrentModificationException exception = new ConcurrentModificationException( | ||
"Resource is being modified by another processor", | ||
new RuntimeException() | ||
); | ||
assertEquals(RestStatus.BAD_REQUEST, exception.status()); | ||
} | ||
|
||
@SneakyThrows | ||
public void testConstructor_whenCreatedWithStream_thenSucceed() { | ||
ConcurrentModificationException exception = new ConcurrentModificationException( | ||
"New datasource is not compatible with existing datasource" | ||
); | ||
|
||
BytesStreamOutput output = new BytesStreamOutput(); | ||
exception.writeTo(output); | ||
BytesStreamInput input = new BytesStreamInput(output.bytes().toBytesRef().bytes); | ||
ConcurrentModificationException copiedException = new ConcurrentModificationException(input); | ||
assertEquals(exception.getMessage(), copiedException.getMessage()); | ||
assertEquals(exception.status(), copiedException.status()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters