-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: Shivansh Arora <hishiv@amazon.com>
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
server/src/test/java/org/opensearch/common/remote/AbstractRemoteEntitiesManagerTests.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,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.remote; | ||
|
||
import org.opensearch.action.LatchedActionListener; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.gateway.remote.ClusterMetadataManifest; | ||
import org.opensearch.gateway.remote.model.RemoteReadResult; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class AbstractRemoteEntitiesManagerTests extends OpenSearchTestCase { | ||
public void testGetStoreWithKnownEntityType() { | ||
AbstractRemoteEntitiesManager manager = new ConcreteRemoteEntitiesManager(); | ||
String knownEntityType = "knownType"; | ||
RemoteWritableEntityStore mockStore = mock(RemoteWritableEntityStore.class); | ||
manager.remoteWritableEntityStores.put(knownEntityType, mockStore); | ||
AbstractRemoteWritableBlobEntity mockEntity = mock(AbstractRemoteWritableBlobEntity.class); | ||
when(mockEntity.getType()).thenReturn(knownEntityType); | ||
|
||
RemoteWritableEntityStore store = manager.getStore(mockEntity); | ||
verify(mockEntity).getType(); | ||
assertEquals(mockStore, store); | ||
} | ||
|
||
public void testGetStoreWithUnknownEntityType() { | ||
AbstractRemoteEntitiesManager manager = new ConcreteRemoteEntitiesManager(); | ||
String unknownEntityType = "unknownType"; | ||
AbstractRemoteWritableBlobEntity mockEntity = mock(AbstractRemoteWritableBlobEntity.class); | ||
when(mockEntity.getType()).thenReturn(unknownEntityType); | ||
|
||
assertThrows(IllegalArgumentException.class, () -> manager.getStore(mockEntity)); | ||
verify(mockEntity, times(2)).getType(); | ||
} | ||
|
||
private static class ConcreteRemoteEntitiesManager extends AbstractRemoteEntitiesManager { | ||
@Override | ||
protected ActionListener<Void> getWriteActionListener(String component, AbstractRemoteWritableBlobEntity remoteObject, LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener) { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected ActionListener<Object> getReadActionListener(String component, AbstractRemoteWritableBlobEntity remoteObject, LatchedActionListener<RemoteReadResult> latchedActionListener) { | ||
return null; | ||
} | ||
} | ||
} |