mirror of
https://github.com/valitydev/event_stock_client_lib.git
synced 2024-11-06 01:35:18 +00:00
Fixed some bugs (#10)
* Fixed some bugs * Fix for waiting new features from woody * Revert change for ESServiceAdapter * Set getClientBuilder protected
This commit is contained in:
parent
841d4b1b7d
commit
4b641c69f3
4
pom.xml
4
pom.xml
@ -12,7 +12,7 @@
|
||||
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>eventstock-client</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.0.4</version>
|
||||
|
||||
<dependencies>
|
||||
<!--RBK libs-->
|
||||
@ -34,7 +34,7 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>damsel</artifactId>
|
||||
<version>[1.75-78b7bac,)</version>
|
||||
<version>1.99-557f549</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--Thirdparty libs-->
|
||||
|
@ -42,7 +42,7 @@ class ESServiceAdapter implements ServiceAdapter<StockEvent, com.rbkmoney.events
|
||||
StockEvent stockEvent = repository.getFirstEvent();
|
||||
log.debug("Received event: {}", stockEvent);
|
||||
return stockEvent;
|
||||
} catch (NoLastEvent e) {
|
||||
} catch (NoStockEvent e) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e);
|
||||
@ -56,7 +56,7 @@ class ESServiceAdapter implements ServiceAdapter<StockEvent, com.rbkmoney.events
|
||||
StockEvent stockEvent = repository.getLastEvent();
|
||||
log.debug("Received event: {}", stockEvent);
|
||||
return stockEvent;
|
||||
} catch (NoLastEvent e) {
|
||||
} catch (NoStockEvent e) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e);
|
||||
|
@ -55,6 +55,26 @@ public class PollingEventPublisherBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public EventHandler getEventHandler() {
|
||||
return eventHandler;
|
||||
}
|
||||
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return errorHandler;
|
||||
}
|
||||
|
||||
public int getMaxQuerySize() {
|
||||
return maxQuerySize;
|
||||
}
|
||||
|
||||
public int getMaxPoolSize() {
|
||||
return maxPoolSize;
|
||||
}
|
||||
|
||||
public int getPollDelay() {
|
||||
return pollDelay;
|
||||
}
|
||||
|
||||
public PollingEventPublisherBuilder withEventHandler(EventHandler eventHandler) {
|
||||
if (eventHandler == null) {
|
||||
throw new NullPointerException("Null event handler");
|
||||
@ -92,10 +112,15 @@ public class PollingEventPublisherBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PollingEventPublisher<StockEvent> build() {
|
||||
THSpawnClientBuilder clientBuilder = new THSpawnClientBuilder();
|
||||
clientBuilder.withAddress(uri);
|
||||
|
||||
|
||||
protected THSpawnClientBuilder getClientBuilder() {
|
||||
THSpawnClientBuilder clientBuilder = new THSpawnClientBuilder().withAddress(uri);
|
||||
return clientBuilder;
|
||||
}
|
||||
|
||||
public PollingEventPublisher<StockEvent> build() {
|
||||
THSpawnClientBuilder clientBuilder = getClientBuilder();
|
||||
ESServiceAdapter serviceAdapter = new ESServiceAdapter(clientBuilder.build(EventRepositorySrv.Iface.class));
|
||||
Poller poller = new Poller(serviceAdapter, maxPoolSize, pollDelay);
|
||||
|
||||
|
@ -191,11 +191,7 @@ class PollingWorker implements Runnable {
|
||||
StockEvent event = range.isFromNow() ? serviceAdapter.getLastEvent() : serviceAdapter.getFirstEvent();
|
||||
if (event == null) {
|
||||
log.trace("No events in stock");
|
||||
if (range.isFromNow()) {
|
||||
rangeWalker = null;
|
||||
} else {
|
||||
rangeWalker = walkerCreator.apply(emptyRangeSupplier.get());
|
||||
}
|
||||
rangeWalker = null;
|
||||
} else {
|
||||
T val = valExtractor.apply(event);
|
||||
range.setFromInclusive(val);
|
||||
|
@ -4,6 +4,7 @@ import com.rbkmoney.damsel.domain.*;
|
||||
import com.rbkmoney.damsel.domain.Currency;
|
||||
import com.rbkmoney.damsel.event_stock.EventConstraint;
|
||||
import com.rbkmoney.damsel.event_stock.EventRange;
|
||||
import com.rbkmoney.damsel.payment_processing.Event;
|
||||
import com.rbkmoney.eventstock.client.*;
|
||||
import com.rbkmoney.damsel.base.InvalidRequest;
|
||||
import com.rbkmoney.damsel.domain.Currency;
|
||||
@ -19,7 +20,11 @@ import com.rbkmoney.thrift.filter.PathConditionFilter;
|
||||
import com.rbkmoney.thrift.filter.condition.Relation;
|
||||
import com.rbkmoney.thrift.filter.converter.TemporalConverter;
|
||||
import com.rbkmoney.thrift.filter.rule.PathConditionRule;
|
||||
import com.rbkmoney.woody.api.event.*;
|
||||
import com.rbkmoney.woody.api.trace.MetadataProperties;
|
||||
import com.rbkmoney.woody.api.trace.context.TraceContext;
|
||||
import com.rbkmoney.woody.thrift.impl.http.THServiceBuilder;
|
||||
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
|
||||
import org.apache.thrift.TException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -108,19 +113,19 @@ public class ClientTest extends AbstractTest {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLimitedRange() throws URISyntaxException, InterruptedException {
|
||||
final List<Long> receivedIdList = new ArrayList<>();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ERSImpl ers = new ERSImpl(1000);
|
||||
|
||||
addServlet(new THServiceBuilder().build(EventRepositorySrv.Iface.class, ers), "/test");
|
||||
addServlet(new THServiceBuilder().withEventListener(
|
||||
(ServiceEventListener<ServiceEvent>) serviceEvent -> log.info(serviceEvent.getActiveSpan().getMetadata().getValue(MetadataProperties.CALL_ERROR))
|
||||
).build(EventRepositorySrv.Iface.class, ers), "/test");
|
||||
|
||||
PollingEventPublisherBuilder eventPublisherBuilder = new PollingEventPublisherBuilder();
|
||||
eventPublisherBuilder.withEventHandler(new EHImpl(latch, receivedIdList));
|
||||
eventPublisherBuilder.withURI(new URI(getUrlString("/test")));
|
||||
eventPublisherBuilder.withEventHandler(new EHImpl(latch, receivedIdList));
|
||||
eventPublisherBuilder.withMaxQuerySize(2);
|
||||
|
||||
PollingEventPublisher<StockEvent> eventPublisher = eventPublisherBuilder.build();
|
||||
@ -254,13 +259,14 @@ public class ClientTest extends AbstractTest {
|
||||
new InvoiceCreated(
|
||||
new Invoice(
|
||||
id+"",
|
||||
com.rbkmoney.thrift.filter.converter.TemporalConverter.temporalToString(Instant.now()),
|
||||
new PartyRef("1", 1),
|
||||
"1",
|
||||
"kek",
|
||||
1,
|
||||
InvoiceStatus.unpaid(new InvoiceUnpaid()),
|
||||
com.rbkmoney.thrift.filter.converter.TemporalConverter.temporalToString(Instant.now()),
|
||||
"1",
|
||||
new Funds(100, new Currency("", "RUB", (short) 1, (short) 0)),
|
||||
ByteBuffer.allocate(0)
|
||||
"kek",
|
||||
"kek",
|
||||
new Cash(100, new Currency("", "RUB", (short) 1, (short) 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user