[ 
https://issues.apache.org/jira/browse/CASSANDRA-1775?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12935491#action_12935491
 ] 

Igor Demydenko commented on CASSANDRA-1775:
-------------------------------------------

Yes, we can.
For example:
In unit tests, when Cassandra.Client is mocked by EasyMock and we expect the 
SlicePredicate, that isn't created in test method (it is created in tested 
method).

Also it affects the hashCode() too.
SlicePredicate is used in Deletion,
Deletion is used in Mutation.
So if we want to accumulate Mutation into the HashSet (e.g. to filter reiterate 
Mutations).
In the following code we have created 3 Deletion (Mutation) for the same column 
and have added they to the HashSet().
The expected Set size must be 1 (because it is the same (equals) operations), 
but actual result is 3.
IMHO it looks strange.
 
{code}
        SlicePredicate predicate = new SlicePredicate();
        
predicate.setColumn_names(Arrays.asList(COLUMN_NAME.getBytes(ENCODING)));
        Deletion deletion = new Deletion();
        deletion.setPredicate(predicate);
        deletion.setTimestamp(timestamp);
        Mutation mutation = new Mutation();
        mutation.setDeletion(deletion);

        SlicePredicate predicate2 = new SlicePredicate();
        
predicate2.setColumn_names(Arrays.asList(COLUMN_NAME.getBytes(ENCODING)));
        Deletion deletion2 = new Deletion();
        deletion2.setPredicate(predicate2);
        deletion2.setTimestamp(timestamp);
        Mutation mutation2 = new Mutation();
        mutation2.setDeletion(deletion2);

        
        SlicePredicate predicate3 = new SlicePredicate();
        
predicate3.setColumn_names(Arrays.asList(COLUMN_NAME.getBytes(ENCODING)));
        Deletion deletion3 = new Deletion();
        deletion3.setPredicate(predicate3);
        deletion3.setTimestamp(timestamp);
        Mutation mutation3 = new Mutation();
        mutation3.setDeletion(deletion3);

        Set<Mutation> mutations = new HashSet<Mutation>(Arrays.asList(mutation, 
mutation2, mutation3));
        assertEquals(mutations.size(), 1);
{code}

> SlicePredicate doesn't support the java.lang.Object.equals() method contract
> ----------------------------------------------------------------------------
>
>                 Key: CASSANDRA-1775
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-1775
>             Project: Cassandra
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 0.6.6
>         Environment: apcahe cassandra 0.6.6
> lib thrift r917130
>            Reporter: Igor Demydenko
>            Priority: Minor
>
> SlicePredicate doesn't support the java.lang.Object.equals() method contract.
> Execute following test:
> {code:title=SlicePredicateTest.java}
> public class SlicePredicateTest {
>     private static final String ENCODING = "UTF-8";
>     private static final String COLUMN_NAME = "ColumnName";
>     @Test
>     public void testEquals() throws Exception {
>         SlicePredicate predicate = new SlicePredicate();
>         
> predicate.setColumn_names(Arrays.asList(COLUMN_NAME.getBytes(ENCODING)));
>         SlicePredicate predicate2 = new SlicePredicate();
>         
> predicate2.setColumn_names(Arrays.asList(COLUMN_NAME.getBytes(ENCODING)));
>         SlicePredicate predicate3 = new SlicePredicate();
>         
> predicate3.setColumn_names(Arrays.asList(COLUMN_NAME.getBytes(ENCODING)));
>         assertFalse(predicate.equals(null)); // not null
>         assertTrue(predicate.equals(predicate)); // reflexivity
>         assertTrue(predicate.equals(predicate2) && 
> predicate2.equals(predicate)); // symmetry
>         assertTrue(predicate.equals(predicate2) && 
> predicate2.equals(predicate3) 
>                 && predicate.equals(predicate3)); // transitivity
>     }
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to