@Override public void run() { OracleClient oclient = env.getSharedResources().getOracleClient(); for (int i = 0; i < numToGet; i++) { try { output.add(oclient.getStamp().getTxTimestamp()); } catch (Exception e) { e.printStackTrace(); } } cdl.countDown(); } }
public synchronized OracleClient getOracleClient() { checkIfClosed(); if (oracleClient == null) { oracleClient = new OracleClient(env); } return oracleClient; }
/** * If an {@link OracleServer} goes away and comes back, the client should automatically reconnect * and start a new block of timestamps (making sure that no timestamp should ever go backwards). */ @Test public void singleOracle_goesAwayAndComesBack() throws Exception { sleepUntil(oserver::isConnected); OracleClient client = env.getSharedResources().getOracleClient(); long timestamp; for (long i = 2; i <= 7; i++) { timestamp = client.getStamp().getTxTimestamp(); assertEquals(i, timestamp); } oserver.stop(); sleepWhile(oserver::isConnected); while (client.getOracle() != null) { Thread.sleep(100); } assertNull(client.getOracle()); oserver.start(); sleepUntil(oserver::isConnected); assertEquals(1002, client.getStamp().getTxTimestamp()); assertTrue(client.getOracle().endsWith(Integer.toString(oserver.getPort()))); oserver.stop(); }
/** * Return the oracle that the current client is connected to. */ public synchronized String getOracle() { checkClosed(); return currentLeader != null ? currentLeader.getId() : null; }
protected CompletableFuture<Stamp> getStampOp() { return env.getSharedResources().getOracleClient().getStampAsync(); }
oracleClient.close();
timestamp = client.getStamp().getTxTimestamp(); assertEquals(i, timestamp); assertTrue(client.getOracle().endsWith(Integer.toString(oserver.getPort()))); sleepUntil(oserver2::isLeader); assertEquals(1002, client.getStamp().getTxTimestamp()); assertTrue(client.getOracle().endsWith(Integer.toString(port2))); assertEquals(2002, client.getStamp().getTxTimestamp()); assertTrue(client.getOracle().endsWith(Integer.toString(port3)));
/** * Return the oracle that the current client is connected to. */ public synchronized String getOracle() { checkClosed(); return currentLeader != null ? currentLeader.getId() : null; }
protected CompletableFuture<Stamp> getStampOp() { return env.getSharedResources().getOracleClient().getStampAsync(); }
oracleClient.close();
private Stamp getTimestamp() { return env.getSharedResources().getOracleClient().getStamp(); }
public CompletableFuture<Stamp> getStampAsync() { checkClosed(); TimeRequest tr = new TimeRequest(); CompletableFuture<Stamp> cf = new CompletableFuture<>(); tr.cf = cf; try { queue.put(tr); } catch (InterruptedException e) { throw new RuntimeException(e); } return cf; }
public synchronized OracleClient getOracleClient() { checkIfClosed(); if (oracleClient == null) { oracleClient = new OracleClient(env); } return oracleClient; }
private Stamp getTimestamp() { return env.getSharedResources().getOracleClient().getStamp(); }
private synchronized void connect() throws IOException, KeeperException, InterruptedException, TTransportException { getLeader(); while (true) { log.debug("Connecting to oracle at " + currentLeader.getId()); String[] hostAndPort = currentLeader.getId().split(":"); String host = hostAndPort[0]; int port = Integer.parseInt(hostAndPort[1]); try { transport = new TFastFramedTransport(new TSocket(host, port)); transport.open(); TProtocol protocol = new TCompactProtocol(transport); client = new OracleService.Client(protocol); log.info("Connected to oracle at " + getOracle()); break; } catch (TTransportException e) { sleepRandom(); getLeader(); } catch (Exception e) { throw new RuntimeException(e); } } }
public CompletableFuture<Stamp> getStampAsync() { checkClosed(); TimeRequest tr = new TimeRequest(); CompletableFuture<Stamp> cf = new CompletableFuture<>(); tr.cf = cf; try { queue.put(tr); } catch (InterruptedException e) { throw new RuntimeException(e); } return cf; }
/** * Test that bogus input into the oracle server doesn't cause an OOM exception. This essentially * tests for THRIFT-602 */ @Test public void bogusDataTest() throws Exception { Socket socket = new Socket(); socket.connect(new InetSocketAddress(HostUtil.getHostName(), oserver.getPort())); OutputStream outstream = socket.getOutputStream(); try (PrintWriter out = new PrintWriter(outstream)) { out.print("abcd"); out.flush(); } socket.close(); OracleClient client = env.getSharedResources().getOracleClient(); assertEquals(2, client.getStamp().getTxTimestamp()); }
private synchronized void connect() throws IOException, KeeperException, InterruptedException, TTransportException { getLeader(); while (true) { log.debug("Connecting to oracle at " + currentLeader.getId()); String[] hostAndPort = currentLeader.getId().split(":"); String host = hostAndPort[0]; int port = Integer.parseInt(hostAndPort[1]); try { transport = new TFastFramedTransport(new TSocket(host, port)); transport.open(); TProtocol protocol = new TCompactProtocol(transport); client = new OracleService.Client(protocol); log.info("Connected to oracle at " + getOracle()); break; } catch (TTransportException e) { sleepRandom(); getLeader(); } catch (Exception e) { throw new RuntimeException(e); } } }