Program: 176321
Project: 176321
Buggy source:
/** 
 * Tests whether TTL provided while inserting records are correctly getting applied using CQL 3 Common TTL value for entire row is used
 * @throws Exception
 */
@Test public void testTTLonCQL3_0() throws Exception {
  if (propertyMap == null) {
    propertyMap=new HashMap();
    propertyMap.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE,"String_Node_Str");
    propertyMap.put(CassandraConstants.CQL_VERSION,CassandraConstants.CQL_VERSION_3_0);
  }
  emf=Persistence.createEntityManagerFactory(SEC_IDX_CASSANDRA_TEST,propertyMap);
  em=emf.createEntityManager();
  Map<String,Integer> ttlValues=new HashMap<String,Integer>();
  ttlValues.put("String_Node_Str",new Integer(5));
  em.setProperty("String_Node_Str",true);
  em.setProperty("String_Node_Str",ttlValues);
  Object p1=prepareData("String_Node_Str",10);
  em.persist(p1);
  em.clear();
  PersonCassandra p=findById(PersonCassandra.class,"String_Node_Str",em);
  SlicePredicate predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  ByteBuffer key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  List<ColumnOrSuperColumn> columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  boolean personNameFound=false;
  boolean ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(5,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(5,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(5000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  Object p2=prepareData("String_Node_Str",10);
  em.persist(p2);
  em.clear();
  ttlValues=new HashMap<String,Integer>();
  ttlValues.put("String_Node_Str",new Integer(10));
  em.setProperty("String_Node_Str",true);
  em.setProperty("String_Node_Str",ttlValues);
  Query q=em.createQuery("String_Node_Str");
  q.executeUpdate();
  predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  personNameFound=false;
  ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(10000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  ttlValues=new HashMap<String,Integer>();
  ttlValues.put("String_Node_Str",new Integer(10));
  em.setProperty("String_Node_Str",true);
  em.setProperty("String_Node_Str",ttlValues);
  Object p3=prepareData("String_Node_Str",10);
  em.persist(p3);
  em.clear();
  predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  personNameFound=false;
  ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(10000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  Object p4=prepareData("String_Node_Str",10);
  em.persist(p4);
  em.clear();
  predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  personNameFound=false;
  ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(10000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  String deleteQuery="String_Node_Str";
  q=em.createQuery(deleteQuery);
  Assert.assertEquals(0,q.executeUpdate());
}

Fixed version (ground truth):
/** 
 * Tests whether TTL provided while inserting records are correctly getting applied using CQL 3 Common TTL value for entire row is used
 * @throws Exception
 */
@Test public void testTTLonCQL3_0() throws Exception {
  if (propertyMap == null) {
    propertyMap=new HashMap();
    propertyMap.put(PersistenceProperties.KUNDERA_DDL_AUTO_PREPARE,"String_Node_Str");
    propertyMap.put(CassandraConstants.CQL_VERSION,CassandraConstants.CQL_VERSION_3_0);
  }
  emf=Persistence.createEntityManagerFactory(SEC_IDX_CASSANDRA_TEST,propertyMap);
  em=emf.createEntityManager();
  Map<String,Integer> ttlValues=new HashMap<String,Integer>();
  ttlValues.put("String_Node_Str",new Integer(5));
  em.setProperty("String_Node_Str",true);
  em.setProperty("String_Node_Str",ttlValues);
  Object p1=prepareData("String_Node_Str",10);
  em.persist(p1);
  em.clear();
  PersonCassandra p=findById(PersonCassandra.class,"String_Node_Str",em);
  SlicePredicate predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  ByteBuffer key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  List<ColumnOrSuperColumn> columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  boolean personNameFound=false;
  boolean ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(5,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(5,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(5000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  Object p2=prepareData("String_Node_Str",10);
  em.persist(p2);
  em.clear();
  ttlValues=new HashMap<String,Integer>();
  ttlValues.put("String_Node_Str",new Integer(10));
  em.setProperty("String_Node_Str",true);
  em.setProperty("String_Node_Str",ttlValues);
  Query q=em.createQuery("String_Node_Str");
  q.executeUpdate();
  predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  personNameFound=false;
  ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(0,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(10000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  ttlValues=new HashMap<String,Integer>();
  ttlValues.put("String_Node_Str",new Integer(10));
  em.setProperty("String_Node_Str",true);
  em.setProperty("String_Node_Str",ttlValues);
  Object p3=prepareData("String_Node_Str",10);
  em.persist(p3);
  em.clear();
  predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  personNameFound=false;
  ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(10000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  Object p4=prepareData("String_Node_Str",10);
  em.persist(p4);
  em.clear();
  predicate=new SlicePredicate();
  predicate.setSlice_range(new SliceRange(Bytes.EMPTY.getBytes(),Bytes.EMPTY.getBytes(),true,10000));
  key=ByteBuffer.wrap("String_Node_Str".getBytes());
  CassandraCli.client.set_keyspace("String_Node_Str");
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  personNameFound=false;
  ageFound=false;
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      personNameFound=true;
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.assertEquals(10,column.getTtl());
      ageFound=true;
    }
  }
  Assert.assertTrue(personNameFound && ageFound);
  Thread.sleep(10000);
  columnOrSuperColumns=CassandraCli.client.get_slice(key,new ColumnParent("String_Node_Str"),predicate,ConsistencyLevel.ONE);
  for (  ColumnOrSuperColumn cosc : columnOrSuperColumns) {
    Column column=cosc.column;
    String columnName=new String(column.getName(),Constants.ENCODING);
    if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
 else     if (columnName.equals("String_Node_Str")) {
      Assert.fail("String_Node_Str");
    }
  }
  String deleteQuery="String_Node_Str";
  q=em.createQuery(deleteQuery);
  Assert.assertEquals(1,q.executeUpdate());
}