protected QJournalProtocol createProxy() throws IOException { final Configuration confCopy = new Configuration(conf); // Need to set NODELAY or else batches larger than MTU can trigger // 40ms nagling delays. confCopy.setBoolean( CommonConfigurationKeysPublic.IPC_CLIENT_TCPNODELAY_KEY, true); RPC.setProtocolEngine(confCopy, QJournalProtocolPB.class, ProtobufRpcEngine.class); return SecurityUtil.doAsLoginUser( new PrivilegedExceptionAction<QJournalProtocol>() { @Override public QJournalProtocol run() throws IOException { RPC.setProtocolEngine(confCopy, QJournalProtocolPB.class, ProtobufRpcEngine.class); QJournalProtocolPB pbproxy = RPC.getProxy( QJournalProtocolPB.class, RPC.getProtocolVersion(QJournalProtocolPB.class), addr, confCopy); return new QJournalProtocolTranslatorPB(pbproxy); } }); }
@Override protected QJournalProtocol createProxy() throws IOException { final QJournalProtocol realProxy = super.createProxy(); QJournalProtocol mock = mockProxy( new WrapEveryCall<Object>(realProxy) { void beforeCall(InvocationOnMock invocation) throws Exception { rpcCount++; String callStr = "[" + addr + "] " + invocation.getMethod().getName() + "(" + Joiner.on(", ").join(invocation.getArguments()) + ")"; Callable<Void> inject = injections.get(rpcCount); if (inject != null) { LOG.info("Injecting code before IPC #" + rpcCount + ": " + callStr); inject.call(); } else { LOG.info("IPC call #" + rpcCount + ": " + callStr); } } }); return mock; }
@Before public void setupMock() { conf.setInt(DFSConfigKeys.DFS_QJOURNAL_QUEUE_SIZE_LIMIT_KEY, LIMIT_QUEUE_SIZE_MB); // Channel to the mock object instead of a real IPC proxy. ch = new IPCLoggerChannel(conf, FAKE_NSINFO, JID, FAKE_ADDR) { @Override protected QJournalProtocol getProxy() throws IOException { return mockProxy; } }; ch.setEpoch(1); }
private static QJournalProtocol mockProxy(WrapEveryCall<Object> wrapper) throws IOException { QJournalProtocol mock = Mockito.mock(QJournalProtocol.class, Mockito.withSettings() .defaultAnswer(wrapper) .extraInterfaces(Closeable.class)); return mock; }
@Before public void setupMock() { conf.setInt(JournalConfigKeys.DFS_QJOURNAL_QUEUE_SIZE_LIMIT_KEY, LIMIT_QUEUE_SIZE_MB); // Channel to the mock object instead of a real IPC proxy. ch = new IPCLoggerChannel(conf, FAKE_NSINFO, JID, FAKE_ADDR) { @Override protected QJournalProtocol getProxy() throws IOException { return mockProxy; } }; ch.setEpoch(1); }
protected QJournalProtocol createProxy() throws IOException { final Configuration confCopy = new Configuration(conf); // Need to set NODELAY or else batches larger than MTU can trigger // 40ms nagling delays. confCopy.setBoolean("ipc.client.tcpnodelay", true); long connectionTimeout = conf.getLong( JournalConfigKeys.DFS_QJOURNAL_CONNECT_TIMEOUT_KEY, Long.MAX_VALUE); return (QJournalProtocol) RPC.waitForProxy(QJournalProtocol.class, QJournalProtocol.versionID, addr, confCopy, connectionTimeout, 0); }
@Override public long getProtocolVersion(String protocol, long clientVersion) throws VersionIncompatible, IOException { if (protocol.equals(QJournalProtocol.class.getName())){ return QJournalProtocol.versionID; } else { throw new IOException("Unknown protocol: " + protocol); } }
public static void init() { try { FastProtocolRegister.register(FastProtocolId.SERIAL_VERSION_ID_1, QJournalProtocol.class.getMethod("journal", JournalRequestInfo.class)); } catch (Exception e) { throw new RuntimeException(e); } }