spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
374 stars 307 forks source link

IntegrationTests: Codec not found for requested operation: [TEXT <-> com.my.example.SquareToken] #1446

Closed donahchoo closed 9 months ago

donahchoo commented 9 months ago

I'm pretty sure this is some configuration error on my part, but I can't figure it out. From the documentation it seems like I should be able to access a repository in an integration test, but maybe not? I'm using SDC 3.4.12.

I have an integration test that is Autowiring in a repository.

public class ExampleIntegrationTest extends ControllerTestParent {
    @Autowired
    private SquareRepository squareRepository;

At the end of a test I want to do this to clean up:

squareRepository.delete(square);

This ends up throwing:

CassandraUncategorizedException: Codec not found for requested operation: [TEXT <-> com.my.example.SquareToken]

However, if I use mockMVC to call the endpoint that does a delete it works:

        MockHttpServletRequestBuilder deleteRequest = delete(squareToken).contentType(APPLICATION_JSON);
        this.mockMvc.perform(deleteRequest)
                    .andDo(print())
                    .andExpect(status().isNoContent());

I'm pretty sure that requests through the delete endpoint work because I have setup the converters, but I don't understand why the converters don't seem to be working when I use the repository in the integration test.

The @Table:

@Table
public class Square  {
    @PrimaryKey
    private SquareToken squareToken;

The converter: (I have one for SquareToken to String and String to SquareToken

public class SquareTokenToStringConverter implements Converter< SquareToken, String> {
    @Override
    public String convert(final SquareToken source) {
        return source.toString();
    }
}

And adding the converters to customConversions(). If I set a break point here I can see this method is getting called when I run the integration tests.

    @Override
    @Bean
    public @NotNull CassandraCustomConversions customConversions() {
        List<Converter<?, ?>> converters = new ArrayList<>();
        converters.add(new SquareTokenToStringConverter());
        converters.add(new StringToSquareTokenConverter());
        return new CassandraCustomConversions(converters);
    }
mp911de commented 9 months ago

We revised the converter with #1384 earlier this year and backported the changes into 4.0.7. The 3.x development line doesn't contain these changes and that development line goes EOL by next month. Please upgrade to the latest Spring Data Cassandra version at your earliest convenience.