Testing Event Translation Mechanisms in LMAX-Disruptor
This test suite validates the EventTranslator functionality in the LMAX Disruptor library, focusing on the translation of data into events. The tests ensure proper event transformation and value assignment within the high-performance inter-thread messaging library.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
lmax-exchange/disruptor
src/test/java/com/lmax/disruptor/EventTranslatorTest.java
/*
* Copyright 2011 LMAX Ltd.
*
* Licensed 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 com.lmax.disruptor;
import com.lmax.disruptor.support.StubEvent;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public final class EventTranslatorTest
{
private static final String TEST_VALUE = "Wibble";
@Test
public void shouldTranslateOtherDataIntoAnEvent()
{
StubEvent event = StubEvent.EVENT_FACTORY.newInstance();
EventTranslator<StubEvent> eventTranslator = new ExampleEventTranslator(TEST_VALUE);
eventTranslator.translateTo(event, 0);
assertEquals(TEST_VALUE, event.getTestString());
}
public static final class ExampleEventTranslator
implements EventTranslator<StubEvent>
{
private final String testValue;
public ExampleEventTranslator(final String testValue)
{
this.testValue = testValue;
}
@Override
public void translateTo(final StubEvent event, final long sequence)
{
event.setTestString(testValue);
}
}
}