Skip to content
This repository has been archived by the owner. It is now read-only.

added mock for candles producer#17

Open
SamurajKing wants to merge 12 commits intomainfrom
tinkoff-service
Open

added mock for candles producer#17
SamurajKing wants to merge 12 commits intomainfrom
tinkoff-service

Conversation

@SamurajKing
Copy link
Collaborator

Нормально ли то, что init() будет вызываться перед каждым тестом, или можно как-то сделать, чтобы он вызвался один раз? (testAll() не помогает, т.к. его нужно делать статическим)

Copy link
Owner

@UncleSema UncleSema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TinkoffClient стоит сделать синглтоном. В будущем мы добавить бд и получается, что либо ты собираешься там хранить TinkoffClient (у тебя это не получится) либо каждый раз, когда будешь вычитывать инфу из базы, создавать TinkoffClient для каждого из клиентов, что нехорошо для перформанса + лишние запросы

}

public void subscribe(String token, List<String> figis) {
public void subscribe(TinkoffClient client, List<String> figis) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вынеси TinkoffClient как поле класса

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public void subscribe(TinkoffClient client, List<String> figis) {
log.info("New subscribe");
CandleSubscriber subs = new CandleSubscriber(candlesProducer);
Consumer<Throwable> onErrorCallback = error -> log.error(error.toString());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоит делать кстати чет типа log.error("Exception during trying to subscribe", error). Просто log.error(String, Throwable) выводит не только message ошибки, но и stack trace, что мб полезно

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

throw new NoTinkoffAccountException();
}
var mainAccountId = br.get(0).getId();
public void subscribe(TinkoffClient client) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично. Клиента в поле. Поменять способ логирования

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public void unsubscribe(String token) {
//TODO: check is that right?
api.remove(token);
public void unsubscribe(TinkoffClient client) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В поле

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

import java.util.List;
import java.util.function.Consumer;

public class TinkoffClient {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

try {
api.getInstrumentsService().getCurrencyByFigi(figi);
} catch (ApiRuntimeException e) {
answer = !e.getCode().equals("50002");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public boolean isListOfFigisValid(List<String> figis) {
boolean yes = true;
for (String figi : figis) {
yes &= isFigiValid(figi);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Слабо при помощи Stream API?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


public void subscribeOperations(OperationSubscriber subscriber, Consumer<Throwable> onErrorCallback) {
List<Account> accounts = getAccountsList();
List<Account> br = accounts.stream().filter(s -> s.getType() == AccountType.ACCOUNT_TYPE_TINKOFF).toList();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream.findFirst() или stream.findAny()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


producer.sendMessage(Utilities.create(response.getCandle()));
} else {
log.info("Some other response...");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.warn("Got unknown message: {}", response)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


Candle tinkoffCandle = Candle.newBuilder().
setLow(
Quotation.newBuilder().
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделай утилитный метод quotation(int, int), а то много одинакового кода

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants