Git Product home page Git Product logo

Comments (7)

digitalbuddha avatar digitalbuddha commented on May 18, 2024

Top of the morning! Could you try with a non empty barcode. Also are you using the latest version, there was a missing hash code previously. The way the functionality is expected to work: memory caching is done in a Guava LoadingCache which backs each store. If multiple requests are made to the same mem cache, the loader will block each subsequent request until a single result is made. I'll validate if a bug. Thanks for reporting

from store.

PaulWoitaschek avatar PaulWoitaschek commented on May 18, 2024

Same with non-empty barcodes. Tested with be47cff
Adjusted the provided testcase above.

from store.

digitalbuddha avatar digitalbuddha commented on May 18, 2024

Thanks for reporting. Will look at it today. I'm curious why StoreTest.testDoubleTap is passing yet this is not. Yay for more tests ☺️

from store.

digitalbuddha avatar digitalbuddha commented on May 18, 2024

Hey 1 more request. Could you please convert the test case to Java. I want to make sure I test against exactly what is failing for you

from store.

PaulWoitaschek avatar PaulWoitaschek commented on May 18, 2024

Can't you add kotlin for tests? Java is such a pain

import com.nytimes.android.external.store.base.Store;
import com.nytimes.android.external.store.base.impl.BarCode;
import com.nytimes.android.external.store.base.impl.StoreBuilder;
import org.junit.Before;
import org.junit.Test;
import rx.Observable;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author Paul Woitaschek
 */
public class SequentialTest {

    private int networkCalls = 0;
    private Store<Integer> store;

    @Before
    public void setup() {
        networkCalls = 0;
        store = StoreBuilder.<Integer>builder()
                .fetcher(barCode -> Observable.fromCallable(() -> networkCalls++))
                .open();
    }

    @Test
    public void sequentially() {
        BarCode b = new BarCode("one", "two");
        store.get(b).test().awaitTerminalEvent();
        store.get(b).test().awaitTerminalEvent();

        assertThat(networkCalls).isEqualTo(1);
    }

    @Test
    public void parallel() {
        BarCode b = new BarCode("one", "two");
        Observable<Integer> first = store.get(b);
        Observable<Integer> second = store.get(b);

        first.test().awaitTerminalEvent();
        second.test().awaitTerminalEvent();

        assertThat(networkCalls).isEqualTo(1);
    }
}

from store.

digitalbuddha avatar digitalbuddha commented on May 18, 2024

you nailed it.

This is because you immediately call

Wrapped the call in a defer and tests pass. Thank you for using (and finding) issues within the Store. LMK if ever in nyc, I owe you a beer (and a visit to ny times if you'd like)

from store.

digitalbuddha avatar digitalbuddha commented on May 18, 2024

Ok so you're find actually surfaced a few issues. Here is another one: The disk cache was not lazy. Internally this was fine for us, but for you without a disk cache the No-Op disk cache internally was immediately encoding a cache miss within the parallel test. TIL I should write more tests :-) another pr coming

from store.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.