Package com.netflix.astyanax

Examples of com.netflix.astyanax.MutationBatch


    public void testDelete() throws Exception {
        LOG.info("Starting testDelete...");

        String rowKey = "DeleteMe_testDelete";

        MutationBatch m = keyspace.prepareMutationBatch();
        m.withRow(CF_STANDARD1, rowKey).putColumn("Column1", "X", null).putColumn("Column2", "X", null);
        m.execute();

        Column<String> column = keyspace.prepareQuery(CF_STANDARD1).getRow(rowKey).getColumn("Column1").execute().getResult();
        Assert.assertEquals("X", column.getStringValue());
       
        m = keyspace.prepareMutationBatch();
        m.withRow(CF_STANDARD1, rowKey).deleteColumn("Column1");
        m.execute();

        column = keyspace.prepareQuery(CF_STANDARD1).getRow(rowKey).getColumn("Column1").execute().getResult();
        Assert.assertNull(column);

        LOG.info("... testDelete");
View Full Code Here


        int nColumns = 100;
        int pageSize = 25;

        // Insert a bunch of rows
        MutationBatch m = keyspace.prepareMutationBatch();
        ColumnListMutation<String> rm = m.withRow(CF_STANDARD1, rowKey);

        for (int i = 0; i < nColumns; i++) {
            rm.putEmptyColumn("" + i, null);
        }

        m.execute();
       
        // Verify count
        int count = keyspace.prepareQuery(CF_STANDARD1)
                    .setConsistencyLevel(ConsistencyLevel.CL_QUORUM)
                    .getKey(rowKey).getCount().execute().getResult();
        Assert.assertEquals(nColumns, count);

        // Delete half of the columns
        m = keyspace.prepareMutationBatch().setConsistencyLevel(ConsistencyLevel.CL_QUORUM);
        rm = m.withRow(CF_STANDARD1, rowKey);

        for (int i = 0; i < nColumns / 2; i++) {
            rm.deleteColumn("" + i);
        }

        m.execute();
       
        // Verify count
        count = keyspace.prepareQuery(CF_STANDARD1)
                .setConsistencyLevel(ConsistencyLevel.CL_QUORUM)
                .getKey(rowKey).getCount().execute().getResult();
        Assert.assertEquals(nColumns / 2, count);
       
        // GET ROW COUNT WITH PAGINATION
        RowQuery<String, String> query = keyspace.prepareQuery(CF_STANDARD1)
                .setConsistencyLevel(ConsistencyLevel.CL_QUORUM).getKey(rowKey)
                .withColumnRange(new RangeBuilder().setLimit(pageSize).build())
                .autoPaginate(true);

        ColumnList<String> result;
        count = 0;
        while (!(result = query.execute().getResult()).isEmpty()) {
            count += result.size();
        }

        Assert.assertEquals(nColumns / 2, count);

        // Delete all of the columns
        m = keyspace.prepareMutationBatch().setConsistencyLevel(ConsistencyLevel.CL_QUORUM);
        rm = m.withRow(CF_STANDARD1, rowKey);

        for (int i = 0; i < nColumns; i++) {
            rm.deleteColumn("" + i);
        }

        m.execute();
       
        // Verify count
        count = keyspace.prepareQuery(CF_STANDARD1)
                .setConsistencyLevel(ConsistencyLevel.CL_QUORUM)
                .getKey(rowKey).getCount().execute().getResult();
View Full Code Here

        Assert.assertFalse(iter2.hasNext());
    }
   
    @Test
    public void testMutationMerge() throws Exception {
        MutationBatch m1 = keyspace.prepareMutationBatch();
        MutationBatch m2 = keyspace.prepareMutationBatch();
        MutationBatch m3 = keyspace.prepareMutationBatch();
        MutationBatch m4 = keyspace.prepareMutationBatch();
        MutationBatch m5 = keyspace.prepareMutationBatch();

        m1.withRow(CF_STANDARD1, "1").putColumn("1", "X", null);
        m2.withRow(CF_STANDARD1, "2").putColumn("2", "X", null).putColumn("3", "X", null);
        m3.withRow(CF_STANDARD1, "3").putColumn("4", "X", null).putColumn("5", "X", null).putColumn("6", "X", null);
        m4.withRow(CF_STANDARD1, "1").putColumn("7", "X", null).putColumn("8", "X", null).putColumn("9", "X", null).putColumn("10", "X", null);

        MutationBatch merged = keyspace.prepareMutationBatch();

        Assert.assertEquals(merged.getRowCount(), 0);

        merged.mergeShallow(m1);
        Assert.assertEquals(merged.getRowCount(), 1);

        merged.mergeShallow(m2);
        Assert.assertEquals(merged.getRowCount(), 2);

        merged.mergeShallow(m3);
        Assert.assertEquals(merged.getRowCount(), 3);

        merged.mergeShallow(m4);
        Assert.assertEquals(merged.getRowCount(), 3);

        merged.mergeShallow(m5);
        Assert.assertEquals(merged.getRowCount(), 3);
       
        merged.execute();
       
        Rows<String, String> result = keyspace.prepareQuery(CF_STANDARD1).getRowSlice("1", "2", "3").execute().getResult();
       
        Assert.assertTrue(5 == result.getRow("1").getColumns().size());
        Assert.assertTrue(2 == result.getRow("2").getColumns().size());
View Full Code Here

    @Test
    public void testComposite() throws Exception {
        String rowKey = "Composite1";

        boolean bool = false;
        MutationBatch m = keyspace.prepareMutationBatch();
        ColumnListMutation<MockCompositeType> mRow = m.withRow(CF_COMPOSITE, rowKey);
        int columnCount = 0;
        for (char part1 = 'a'; part1 <= 'b'; part1++) {
            for (int part2 = 0; part2 < 10; part2++) {
                for (int part3 = 10; part3 < 11; part3++) {
                    bool = !bool;
                    columnCount++;
                    mRow.putEmptyColumn(
                            new MockCompositeType(Character.toString(part1),
                                    part2, part3, bool, "UTF"), null);
                }
            }
        }
        m.execute();
        LOG.info("Created " + columnCount + " columns");

        OperationResult<ColumnList<MockCompositeType>> result;
       
        result = keyspace.prepareQuery(CF_COMPOSITE).getKey(rowKey).execute();
View Full Code Here

   
    keyspace.createColumnFamily(CF_ALL_ROWS, null);
    CF_ALL_ROWS.describe(keyspace);
   
    /** POPULATE ROWS FOR TESTS */
      MutationBatch m = keyspace.prepareMutationBatch();

        for (char keyName = 'A'; keyName <= 'Z'; keyName++) {
            String rowKey = Character.toString(keyName);
            ColumnListMutation<String> cfmStandard = m.withRow(CF_ALL_ROWS, rowKey);
            for (char cName = 'a'; cName <= 'z'; cName++) {
                cfmStandard.putColumn(Character.toString(cName), (int) (cName - 'a') + 1, null);
            }
            m.withCaching(true);
            m.execute();
            m.discardMutations();
        }
    }
View Full Code Here

    @Test
    public void paginateLongColumns() throws Exception {

        String rowKey = "A";
        MutationBatch m = keyspace.prepareMutationBatch();
        ColumnListMutation<Long> cfmLong = m.withRow(CF_LONGCOLUMN, rowKey);
        for (Long l = -10L; l < 10L; l++) {
            cfmLong.putEmptyColumn(l, null);
        }
        cfmLong.putEmptyColumn(Long.MAX_VALUE, null);
        m.execute();
       
        // READ BACK WITH PAGINATION
        Long column = Long.MIN_VALUE;
        ColumnList<Long> columns;
        int pageSize = 10;
View Full Code Here

      = ColumnFamily.newColumnFamily("compositekey", M_SERIALIZER, StringSerializer.get());
 
    @Test
    public void testCompositeKey() {
        MockCompositeType key = new MockCompositeType("A", 1, 2, true, "B");
        MutationBatch m = keyspace.prepareMutationBatch();
        m.withRow(CF_COMPOSITE_KEY, key).putColumn("Test", "Value", null);
        try {
            m.execute();
        } catch (ConnectionException e) {
            LOG.error(e.getMessage(), e);
            Assert.fail();
        }
View Full Code Here

        IntegerSerializer.get(),
        StringSerializer.get());
  }
 
  public void insert(int empId, int deptId, String firstName, String lastName) {
    MutationBatch m = keyspace.prepareMutationBatch();

    m.withRow(EMP_CF, empId)
      .putColumn(COL_NAME_EMPID, empId, null)
      .putColumn(COL_NAME_DEPTID, deptId, null)
      .putColumn(COL_NAME_FIRST_NAME, firstName, null)
      .putColumn(COL_NAME_LAST_NAME, lastName, null)
      ;

    try {
      @SuppressWarnings("unused")
      OperationResult<Void> result = m.execute();
    } catch (ConnectionException e) {
      logger.error("failed to write data to C*", e);
      throw new RuntimeException("failed to write data to C*", e);
    }
    logger.debug("insert ok");
View Full Code Here

    }
    logger.debug("insert ok");
  }
 
  public void insertDynamicProperties(int id, String[] ... entries) {
    MutationBatch m = keyspace.prepareMutationBatch();

    ColumnListMutation<String> clm = m.withRow(EMP_CF, id);
    for(String[] kv : entries) {
      clm.putColumn(kv[0], kv[1], null);
    }
   
    try {
      @SuppressWarnings("unused")
      OperationResult<Void> result = m.execute();
    } catch (ConnectionException e) {
      logger.error("failed to write data to C*", e);
      throw new RuntimeException("failed to write data to C*", e);
    }
    logger.debug("insert ok");
View Full Code Here

    }

    @Override
    public void logFailedWrite(WriteMetadata failedWrite) {
       
        MutationBatch mutationBatch = ks.prepareMutationBatch();
        addToBatch(mutationBatch, failedWrite);
       
        try {
            mutationBatch.execute();
        } catch (ConnectionException e) {
            Logger.error("Failed to log failed write to fallback cluster: " + failedWrite, e);
        }
    }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.MutationBatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.