Search in sources :

Example 6 with Writer

use of org.apache.accumulo.core.clientImpl.Writer in project accumulo by apache.

the class ReplicationTableUtilTest method properPathInRow.

@Test
public void properPathInRow() throws Exception {
    Writer writer = EasyMock.createNiceMock(Writer.class);
    writer.update(EasyMock.anyObject(Mutation.class));
    final List<Mutation> mutations = new ArrayList<>();
    // Mock a Writer to just add the mutation to a list
    EasyMock.expectLastCall().andAnswer(() -> {
        mutations.add(((Mutation) EasyMock.getCurrentArguments()[0]));
        return null;
    });
    EasyMock.replay(writer);
    Credentials creds = new Credentials("root", new PasswordToken(""));
    ClientContext context = EasyMock.createMock(ClientContext.class);
    EasyMock.expect(context.getCredentials()).andReturn(creds).anyTimes();
    EasyMock.replay(context);
    // Magic hook to create a Writer
    ReplicationTableUtil.addWriter(creds, writer);
    // Example file seen coming out of LogEntry
    UUID uuid = UUID.randomUUID();
    String myFile = "file:////home/user/accumulo/wal/server+port/" + uuid;
    long createdTime = System.currentTimeMillis();
    ReplicationTableUtil.updateFiles(context, new KeyExtent(TableId.of("1"), null, null), myFile, StatusUtil.fileCreated(createdTime));
    verify(writer);
    assertEquals(1, mutations.size());
    Mutation m = mutations.get(0);
    assertEquals(ReplicationSection.getRowPrefix() + "file:/home/user/accumulo/wal/server+port/" + uuid, new Text(m.getRow()).toString());
    List<ColumnUpdate> updates = m.getUpdates();
    assertEquals(1, updates.size());
    ColumnUpdate update = updates.get(0);
    assertEquals(ReplicationSection.COLF, new Text(update.getColumnFamily()));
    assertEquals("1", new Text(update.getColumnQualifier()).toString());
    assertEquals(StatusUtil.fileCreatedValue(createdTime), new Value(update.getValue()));
}
Also used : ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) UUID(java.util.UUID) Writer(org.apache.accumulo.core.clientImpl.Writer) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.Test)

Aggregations

Writer (org.apache.accumulo.core.clientImpl.Writer)6 BatchWriter (org.apache.accumulo.core.client.BatchWriter)3 Credentials (org.apache.accumulo.core.clientImpl.Credentials)3 Mutation (org.apache.accumulo.core.data.Mutation)2 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)1 ColumnUpdate (org.apache.accumulo.core.data.ColumnUpdate)1 Value (org.apache.accumulo.core.data.Value)1 ServerContext (org.apache.accumulo.server.ServerContext)1 Text (org.apache.hadoop.io.Text)1