Examples of WriteResponse


Examples of com.couchace.core.api.response.WriteResponse

        assertEquals(foundSpeakAction.getSaid(), speakAction.getSaid());
        assertNotNull(foundSpeakAction.getRevision(), "Revision is null");

        // Update speak action.
        foundSpeakAction.setSaid("Goodbye");
        WriteResponse putResponse = couchDatabase
            .put()
            .entity(foundSpeakAction)
            .execute();
        assertEquals(putResponse.getDocumentId(), "Action:" + foundSpeakAction.getId());
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        // Get and ensure said was updated.
        foundSpeakAction = couchDatabase
            .get()
            .entity(SpeakActionEntity.class, "Action:" + foundSpeakAction.getId())
            .execute()
            .getFirstEntity();
        assertEquals(foundSpeakAction.getSaid(), "Goodbye");
        assertEquals(foundSpeakAction.getRevision(), putResponse.getDocumentRevision());

        // Should be the same if searching by ActionEntity
        ActionEntity actionEntity = couchDatabase
            .get()
            .entity(ActionEntity.class, "Action:" + foundSpeakAction.getId())
            .execute()
            .getFirstEntity();
        assertEquals(actionEntity.getClass(), SpeakActionEntity.class);
        assertEquals(actionEntity.getRevision(), putResponse.getDocumentRevision());
        assertEquals(((SpeakActionEntity)actionEntity).getSaid(), "Goodbye");


    }
View Full Code Here

Examples of com.couchace.core.api.response.WriteResponse

    private String newId() {
        return String.valueOf(nextId++);
    }

    private WriteResponse putAction(ActionEntity actionEntity) {
        WriteResponse putResponse = couchDatabase
            .put()
            .entity(actionEntity)
            .execute();
        assertEquals(putResponse.getDocumentId(), "Action:" + actionEntity.getId());
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        actions.add(actionEntity);

        return putResponse;
    }
View Full Code Here

Examples of com.couchace.core.api.response.WriteResponse

            .getFirstContentAsLong();

        // Add a vehicle
        String firebirdId = "99";
        VehicleEntity firebird = VehicleEntity.newVehicle(firebirdId, VehicleType.CAR, "Pontiac", "Firebird", "1969", "Black");
        WriteResponse putResponse = couchDatabase
            .put()
            .entity(firebird)
            .execute();
        assertEquals(putResponse.getDocumentId(), firebirdId);
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        // Check count
        long newVehicleCount = couchDatabase
            .get()
            .document(couchViewQuery)
            .execute()
            .getFirstContentAsLong();
        assertEquals(newVehicleCount, initialVehicleCount + 1);

        // Retrieve the vehicle we just added.
        VehicleEntity foundFirebird = couchDatabase
            .get()
            .entity(VehicleEntity.class, firebirdId)
            .execute()
            .getFirstEntity();

        assertEquals(foundFirebird.getId(), firebird.getId());
        assertEquals(foundFirebird.getRevision(), putResponse.getDocumentRevision());
        assertEquals(foundFirebird.getVehicleType(), firebird.getVehicleType());
        assertEquals(foundFirebird.getMake(), firebird.getMake());
        assertEquals(foundFirebird.getModel(), firebird.getModel());
        assertEquals(foundFirebird.getYear(), firebird.getYear());
        assertEquals(foundFirebird.getColor(), firebird.getColor());

        // Retrieve the raw document and ensure the id is not part of the entity body.
        GetDocumentResponse response = couchDatabase
                .get()
                .document(firebirdId)
                .execute();
        TextDocument textDocument = response.getFirstDocument();
        String content = textDocument.getContent();
        ObjectMapper objectMapper = new ObjectMapper();
        Map map = objectMapper.readValue(content, Map.class);
        Map entity = (Map) map.get("entity");
        assertFalse(entity.containsKey("id"), "The entity body stored in couch contains the id.");

        // Change color to blue and update
        foundFirebird.setColor("Green");
        putResponse = couchDatabase
            .put()
            .entity(foundFirebird)
            .execute();
        assertEquals(putResponse.getDocumentId(), firebirdId);
        assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
        assertNotNull(putResponse.getDocumentRevision());

        // Get and ensure color was updated.
        foundFirebird = couchDatabase
            .get()
            .entity(VehicleEntity.class, firebirdId)
            .execute()
            .getFirstEntity();
        assertEquals(foundFirebird.getColor(), "Green");
        assertEquals(foundFirebird.getRevision(), putResponse.getDocumentRevision());
    }
View Full Code Here

Examples of com.couchace.core.api.response.WriteResponse

    }

    @Override
    public WriteResponse createDatabase() {
        CouchHttpResponse httpResponse =  httpClient.createDatabase(databaseName);
        return new WriteResponse(httpResponse);
    }
View Full Code Here

Examples of com.couchace.core.api.response.WriteResponse

    @Override
    public WriteResponse deleteDatabase() {
        if (featureSet.isTrue(CouchFeature.ALLOW_DB_DELETE)) {
            CouchHttpResponse httpResponse = httpClient.deleteDatabase(databaseName);
            return new WriteResponse(httpResponse);
        } else {
            throw CouchException.forbidden("Deletion of database " + databaseName + " is not allowed. To allow configure with CouchFeature.ALLOW_DB_DELETE.");
        }
    }
View Full Code Here

Examples of org.apache.cassandra.db.WriteResponse

    // TODO: We need to log error responses here for example
    // if a write fails for a key log that the key could not be replicated
    boolean returnValue = false;
    for (Message response : responses) {
      Object[] body = response.getMessageBody();
      WriteResponse writeResponse = (WriteResponse) body[0];
      boolean result = writeResponse.isSuccess();
      if (!result) {
        logger_.debug("Write at " + response.getFrom()
            + " may have failed for the key " + writeResponse.key());
      }
      returnValue |= result;
    }
    return returnValue;
  }
View Full Code Here

Examples of org.apache.cassandra.db.WriteResponse

  {
    // TODO: We need to log error responses here for example
    // if a write fails for a key log that the key could not be replicated
    boolean returnValue = false;
    for (Message response : responses) {
            WriteResponse writeResponseMessage = null;
            try
            {
                writeResponseMessage = WriteResponse.serializer().deserialize(new DataInputStream(new ByteArrayInputStream(response.getMessageBody())));
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            boolean result = writeResponseMessage.isSuccess();
            if (!result) {
        if (logger_.isDebugEnabled())
                    logger_.debug("Write at " + response.getFrom()
            + " may have failed for the key " + writeResponseMessage.key());
      }
      returnValue |= result;
    }
    return returnValue;
  }
View Full Code Here

Examples of org.apache.cassandra.db.WriteResponse

  {
    // TODO: We need to log error responses here for example
    // if a write fails for a key log that the key could not be replicated
    boolean returnValue = false;
    for (Message response : responses) {
            WriteResponse writeResponseMessage = null;
            try
            {
                writeResponseMessage = WriteResponse.serializer().deserialize(new DataInputStream(new ByteArrayInputStream(response.getMessageBody())));
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            boolean result = writeResponseMessage.isSuccess();
            if (!result) {
        logger_.debug("Write at " + response.getFrom()
            + " may have failed for the key " + writeResponseMessage.key());
      }
      returnValue |= result;
    }
    return returnValue;
  }
View Full Code Here

Examples of org.apache.cassandra.db.WriteResponse

{
    public void doVerb(MessageIn<Commit> message, int id)
    {
        PaxosState.commit(message.payload);

        WriteResponse response = new WriteResponse();
        Tracing.trace("Enqueuing acknowledge to {}", message.from);
        MessagingService.instance().sendReply(response.createMessage(), id, message.from);
    }
View Full Code Here

Examples of org.apache.cassandra.db.WriteResponse

  {
    // TODO: We need to log error responses here for example
    // if a write fails for a key log that the key could not be replicated
    boolean returnValue = false;
    for (Message response : responses) {
            WriteResponse writeResponseMessage = null;
            try
            {
                writeResponseMessage = WriteResponse.serializer().deserialize(new DataInputStream(new ByteArrayInputStream(response.getMessageBody())));
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            boolean result = writeResponseMessage.isSuccess();
            if (!result) {
        if (logger_.isDebugEnabled())
                    logger_.debug("Write at " + response.getFrom()
            + " may have failed for the key " + writeResponseMessage.key());
      }
      returnValue |= result;
    }
    return returnValue;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.