-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify EventHandle to be created for every event and support internal…
… and external origination times (#3546) * Modify EventHandle to be created for every event and support internal and external origination times Signed-off-by: Krishna Kondaka <[email protected]> * Fixed build failures Signed-off-by: Krishna Kondaka <[email protected]> * Fixed build failures Signed-off-by: Krishna Kondaka <[email protected]> * fixed failing checkstyle error Signed-off-by: Krishna Kondaka <[email protected]> * Fixed build errors Signed-off-by: Krishna Kondaka <[email protected]> * Addressed review comments by adding InternalEventHandle Signed-off-by: Krishna Kondaka <[email protected]> * Fixed checkstyle errors Signed-off-by: Krishna Kondaka <[email protected]> * Fixed build errors Signed-off-by: Krishna Kondaka <[email protected]> --------- Signed-off-by: Krishna Kondaka <[email protected]> Co-authored-by: Krishna Kondaka <[email protected]>
- Loading branch information
Showing
34 changed files
with
399 additions
and
244 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/DefaultEventHandle.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,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.event; | ||
|
||
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSet; | ||
import java.lang.ref.WeakReference; | ||
|
||
import java.time.Instant; | ||
import java.io.Serializable; | ||
|
||
public class DefaultEventHandle implements EventHandle, InternalEventHandle, Serializable { | ||
private Instant externalOriginationTime; | ||
private final Instant internalOriginationTime; | ||
private WeakReference<AcknowledgementSet> acknowledgementSetRef; | ||
|
||
public DefaultEventHandle(final Instant internalOriginationTime) { | ||
this.acknowledgementSetRef = null; | ||
this.externalOriginationTime = null; | ||
this.internalOriginationTime = internalOriginationTime; | ||
} | ||
|
||
@Override | ||
public void setAcknowledgementSet(final AcknowledgementSet acknowledgementSet) { | ||
this.acknowledgementSetRef = new WeakReference<>(acknowledgementSet); | ||
} | ||
|
||
@Override | ||
public void setExternalOriginationTime(final Instant externalOriginationTime) { | ||
this.externalOriginationTime = externalOriginationTime; | ||
} | ||
|
||
public AcknowledgementSet getAcknowledgementSet() { | ||
if (acknowledgementSetRef == null) { | ||
return null; | ||
} | ||
return acknowledgementSetRef.get(); | ||
} | ||
|
||
@Override | ||
public Instant getInternalOriginationTime() { | ||
return this.internalOriginationTime; | ||
} | ||
|
||
@Override | ||
public Instant getExternalOriginationTime() { | ||
return this.externalOriginationTime; | ||
} | ||
|
||
@Override | ||
public void release(boolean result) { | ||
AcknowledgementSet acknowledgementSet = getAcknowledgementSet(); | ||
if (acknowledgementSet != null) { | ||
acknowledgementSet.release(this, result); | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...prepper-api/src/main/java/org/opensearch/dataprepper/model/event/InternalEventHandle.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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.event; | ||
|
||
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSet; | ||
|
||
public interface InternalEventHandle { | ||
/** | ||
* sets acknowledgement set | ||
* | ||
* @param acknowledgementSet acknowledgementSet to be set in the event handle | ||
* @since 2.6 | ||
*/ | ||
void setAcknowledgementSet(final AcknowledgementSet acknowledgementSet); | ||
|
||
/** | ||
* gets acknowledgement set | ||
* | ||
* @return returns acknowledgementSet from the event handle | ||
* @since 2.6 | ||
*/ | ||
AcknowledgementSet getAcknowledgementSet(); | ||
|
||
} | ||
|
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
59 changes: 59 additions & 0 deletions
59
...per-api/src/test/java/org/opensearch/dataprepper/model/event/DefaultEventHandleTests.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,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.event; | ||
|
||
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSet; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import org.junit.jupiter.api.Test; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import org.mockito.Mock; | ||
|
||
import java.time.Instant; | ||
|
||
class DefaultEventHandleTests { | ||
@Mock | ||
private AcknowledgementSet acknowledgementSet; | ||
|
||
@Test | ||
void testBasic() { | ||
Instant now = Instant.now(); | ||
DefaultEventHandle eventHandle = new DefaultEventHandle(now); | ||
assertThat(eventHandle.getAcknowledgementSet(), equalTo(null)); | ||
assertThat(eventHandle.getInternalOriginationTime(), equalTo(now)); | ||
assertThat(eventHandle.getExternalOriginationTime(), equalTo(null)); | ||
eventHandle.release(true); | ||
} | ||
|
||
@Test | ||
void testWithAcknowledgementSet() { | ||
acknowledgementSet = mock(AcknowledgementSet.class); | ||
when(acknowledgementSet.release(any(EventHandle.class), any(Boolean.class))).thenReturn(true); | ||
Instant now = Instant.now(); | ||
DefaultEventHandle eventHandle = new DefaultEventHandle(now); | ||
assertThat(eventHandle.getAcknowledgementSet(), equalTo(null)); | ||
assertThat(eventHandle.getInternalOriginationTime(), equalTo(now)); | ||
assertThat(eventHandle.getExternalOriginationTime(), equalTo(null)); | ||
eventHandle.setAcknowledgementSet(acknowledgementSet); | ||
eventHandle.release(true); | ||
verify(acknowledgementSet).release(eventHandle, true); | ||
} | ||
|
||
@Test | ||
void testWithExternalOriginationTime() { | ||
Instant now = Instant.now(); | ||
DefaultEventHandle eventHandle = new DefaultEventHandle(now); | ||
assertThat(eventHandle.getAcknowledgementSet(), equalTo(null)); | ||
assertThat(eventHandle.getInternalOriginationTime(), equalTo(now)); | ||
assertThat(eventHandle.getExternalOriginationTime(), equalTo(null)); | ||
eventHandle.setExternalOriginationTime(now.minusSeconds(60)); | ||
assertThat(eventHandle.getExternalOriginationTime(), equalTo(now.minusSeconds(60))); | ||
eventHandle.release(true); | ||
} | ||
} |
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
Oops, something went wrong.