Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached queries reuse the EvaluationContext [DATAKV-137] #116

Closed
spring-projects-issues opened this issue Jun 2, 2016 · 0 comments
Closed

Cached queries reuse the EvaluationContext [DATAKV-137] #116

spring-projects-issues opened this issue Jun 2, 2016 · 0 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jun 2, 2016

Shijun Kong opened DATAKV-137 and commented

The following test will fail at the last assertion, with NPE.
I believe it is a bug in CachingKeyValuePartTreeQuery#cachedQuery.

After, the first findByName statement, the cachedQuery.criteria.context.variables contains User("Jack"), which later was deleted.

However, in the context, it is never been properly cleanup. So, the next findByName statement will yield NPE. Because "it" reference -> "Jack"

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(AppConfig.class)
public class UserRepoTest {

    @Autowired
    private UserRepo repo;

    @org.junit.Test
    public void testFindByName() throws Exception {
        repo.save(new User("Jack"));
        repo.save(new User("Mary"));

        User jack = repo.findByName("Jack");
        assertThat(jack.getName(), is("Jack"));

        repo.delete(jack);

        Iterable<User> all = repo.findAll();
        assertThat(StreamSupport.stream(all.spliterator(), false).count(), is(1L));
        assertThat(all.iterator().next().getName(), is("Mary"));

        User mary = repo.findByName("Mary");
        assertThat(mary.getName(), is("Mary"));
    }

}

user is a simple pojo

@KeySpace("user")
public class User {

    @Id
    private String uuid;

    private String name;

    public User(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }
}

@Configuration
@EnableMapRepositories("repositories")
public class AppConfig { }

public interface UserRepo extends CrudRepository<User, String> {

    User findByName(String name);
}

Affects: 1.1.1 (Hopper SR1)

Referenced from: pull request #20

Backported to: 1.1.2 (Hopper SR2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants