@Test public void testAppendReply() { List<Long> ids = Arrays.asList(1L, 2L, 3L); IOException ioException = new IOException("test"); StackTraceElement[] trace = ioException.getStackTrace(); StringBuffer buf = new StringBuffer(); for (StackTraceElement el: trace) { buf.append(el.toString()).append("\n"); } String strace = buf.toString(); LogServiceException expectedLogServiceException = LogServiceException.newBuilder() .setExceptionClassName("java.io.IOException") .setErrorMsg("test") .setStacktrace(ByteString.copyFrom(strace, Charset.defaultCharset())) .build(); AppendLogEntryReplyProto proto1 = LogServiceProtoUtil.toAppendLogReplyProto(ids, null); assertEquals(LogServiceException.getDefaultInstance(), proto1.getException()); assertEquals(ids, proto1.getRecordIdList()); AppendLogEntryReplyProto proto2 = LogServiceProtoUtil.toAppendLogReplyProto(null, ioException); assertEquals(expectedLogServiceException, proto2.getException()); assertEquals(Collections.EMPTY_LIST, proto2.getRecordIdList()); AppendLogEntryReplyProto proto3 = LogServiceProtoUtil.toAppendLogReplyProto(ids, ioException); assertEquals(expectedLogServiceException, proto3.getException()); assertEquals(Collections.EMPTY_LIST, proto3.getRecordIdList()); AppendLogEntryReplyProto proto4 = LogServiceProtoUtil.toAppendLogReplyProto(null, null); assertEquals(LogServiceException.getDefaultInstance(), proto4.getException()); assertEquals(Collections.EMPTY_LIST, proto4.getRecordIdList()); }
public static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t) { AppendLogEntryReplyProto.Builder builder = AppendLogEntryReplyProto.newBuilder(); if (t != null) { builder.setException(toLogException(t)); } else if (ids != null) { for (long id: ids) { builder.addRecordId(id); } } return builder.build(); }
LogServiceProtoUtil { public static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t) { AppendLogEntryReplyProto.Builder builder = AppendLogEntryReplyProto.newBuilder(); if (t != null) { builder.setException(toLogException(t)); } else if (ids != null) { for (long id: ids) { builder.addRecordId(id); } } return builder.build(); } }
LogServiceProtoUtil { public static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t) { AppendLogEntryReplyProto.Builder builder = AppendLogEntryReplyProto.newBuilder(); if (t != null) { builder.setException(toLogException(t)); } else if (ids != null) { for (long id: ids) { builder.addRecordId(id); } } return builder.build(); }  }
LogServiceProtoUtil { public static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t) { AppendLogEntryReplyProto.Builder builder = AppendLogEntryReplyProto.newBuilder(); if (t != null) { builder.setException(toLogException(t)); } else if (ids != null) { for (long id: ids) { builder.addRecordId(id); } } return builder.build(); }  static LogNameProto toLogNameProto(LogName logName); static LogName toLogName(LogServiceProtos.LogNameProto logNameProto); static LogStreamProto toLogStreamProto(LogStream logStream); static LogServiceRequestProto toChangeStateRequestProto(LogName logName, State state,
      boolean force); static LogServiceRequestProto toChangeStateRequestProto(LogName logName, State state); static LogServiceRequestProto toGetStateRequestProto(LogName logName); static ArchiveLogReplyProto toArchiveLogReplyProto(Throwable t); static LogServiceRequestProto toGetSizeRequestProto(LogName name); static LogServiceRequestProto toGetLengthRequestProto(LogName name); static LogServiceRequestProto toGetLastCommittedIndexRequestProto(LogName name); static LogServiceRequestProto toGetStartIndexProto(LogName name); static LogServiceRequestProto toReadLogRequestProto(LogName name, long start, int total); static LogServiceRequestProto toSyncLogRequestProto(LogName name); static LogServiceRequestProto toAppendEntryLogRequestProto(LogName name,
      List<byte[]> entries); static LogServiceRequestProto toAppendBBEntryLogRequestProto(LogName name,
      List<ByteBuffer> entries); static List<byte[]> toListByteArray(List<ByteString> list); static GetStateReplyProto toGetStateReplyProto(State state); static GetLogLengthReplyProto toGetLogLengthReplyProto(long length, Throwable t); static GetLogSizeReplyProto toGetLogSizeReplyProto(long size, Throwable t); static GetLogStartIndexReplyProto toGetLogStartIndexReplyProto(long length, Throwable t); static GetLogLastCommittedIndexReplyProto toGetLogLastIndexReplyProto(long lastIndex, Throwable t); static ReadLogReplyProto toReadLogReplyProto(List<byte[]> entries, Throwable t); static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t); static SyncLogReplyProto toSyncLogReplyProto(long index, Throwable t); static ArchiveLogRequestProto toExportInfoProto(ArchivalInfo info); static ArchivalInfo toExportInfo(ArchiveLogRequestProto proto); GetLogLengthReplyProto toGetLogLengthReplyProto(long length); static LogServiceException toLogException(Throwable t); static LogServiceRequestProto toExportInfoRequestProto(LogName logName); static LogServiceRequestProto toArchiveLogRequestProto(LogName logName, String location,
      long raftIndex, boolean isArchival, ArchivalInfo.ArchivalStatus status); }
LogServiceProtoUtil { public static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t) { AppendLogEntryReplyProto.Builder builder = AppendLogEntryReplyProto.newBuilder(); if (t != null) { builder.setException(toLogException(t)); } else if (ids != null) { for (long id: ids) { builder.addRecordId(id); } } return builder.build(); }  static LogNameProto toLogNameProto(LogName logName); static LogName toLogName(LogServiceProtos.LogNameProto logNameProto); static LogStreamProto toLogStreamProto(LogStream logStream); static LogServiceRequestProto toChangeStateRequestProto(LogName logName, State state,
      boolean force); static LogServiceRequestProto toChangeStateRequestProto(LogName logName, State state); static LogServiceRequestProto toGetStateRequestProto(LogName logName); static ArchiveLogReplyProto toArchiveLogReplyProto(Throwable t); static LogServiceRequestProto toGetSizeRequestProto(LogName name); static LogServiceRequestProto toGetLengthRequestProto(LogName name); static LogServiceRequestProto toGetLastCommittedIndexRequestProto(LogName name); static LogServiceRequestProto toGetStartIndexProto(LogName name); static LogServiceRequestProto toReadLogRequestProto(LogName name, long start, int total); static LogServiceRequestProto toSyncLogRequestProto(LogName name); static LogServiceRequestProto toAppendEntryLogRequestProto(LogName name,
      List<byte[]> entries); static LogServiceRequestProto toAppendBBEntryLogRequestProto(LogName name,
      List<ByteBuffer> entries); static List<byte[]> toListByteArray(List<ByteString> list); static GetStateReplyProto toGetStateReplyProto(State state); static GetLogLengthReplyProto toGetLogLengthReplyProto(long length, Throwable t); static GetLogSizeReplyProto toGetLogSizeReplyProto(long size, Throwable t); static GetLogStartIndexReplyProto toGetLogStartIndexReplyProto(long length, Throwable t); static GetLogLastCommittedIndexReplyProto toGetLogLastIndexReplyProto(long lastIndex, Throwable t); static ReadLogReplyProto toReadLogReplyProto(List<byte[]> entries, Throwable t); static AppendLogEntryReplyProto toAppendLogReplyProto(List<Long> ids, Throwable t); static SyncLogReplyProto toSyncLogReplyProto(long index, Throwable t); static ArchiveLogRequestProto toExportInfoProto(ArchivalInfo info); static ArchivalInfo toExportInfo(ArchiveLogRequestProto proto); GetLogLengthReplyProto toGetLogLengthReplyProto(long length); static LogServiceException toLogException(Throwable t); static LogServiceRequestProto toExportInfoRequestProto(LogName logName); static LogServiceRequestProto toArchiveLogRequestProto(LogName logName, String location,
      long raftIndex, boolean isArchival, ArchivalInfo.ArchivalStatus status);  }