8687888990919293949596
expect(zkMock.getState()).andStubReturn(ZooKeeper.States.CONNECTED); replay(zkMock); ZKBackend zkb = createZKBackend(true); RootNode rootNode = zkb.connect(); assertNotNull(rootNode); assertTrue(zkb.isConnected()); verify(zkMock); }
102103104105106107108109110111112
replay(zkMock); zkb.setConnectionTimeout(5); try { zkb.connect(); fail("A ServiceLocatorException should have been thrown."); } catch (ServiceLocatorException e) { ignore("Expected exception"); }
121122123124125126127128129130131
zkMock.addAuthInfo(eq("sl"), aryEq(USER_NAME_PASSWORD_BYTES)); replay(zkMock); zkb.setUserName(USER_NAME); zkb.setPassword(PASSWORD); zkb.connect(); verify(zkMock); } @Test
132133134135136137138139140141142
public void nodeExistsTrue() throws Exception { expect(zkMock.exists(NODE_PATH.toString(), false)).andReturn(new Stat()); replay(zkMock); ZKBackend zkb = createZKBackend(); zkb.connect(); boolean exists = zkb.nodeExists(NODE_PATH); assertTrue(exists); verify(zkMock); }
146147148149150151152153154155156
expect(zkMock.exists(NODE_PATH.toString(), false)).andReturn(null); ZKBackend zkb = createZKBackend(); replay(zkMock); zkb.connect(); boolean exists = zkb.nodeExists(NODE_PATH); assertFalse(exists); verify(zkMock); }
161162163164165166167168169170171
andReturn(NODE_PATH.toString()); ZKBackend zkb = createZKBackend(); replay(zkMock); zkb.connect(); zkb.createNode(NODE_PATH, PERSISTENT, CONTENT_ANY_1); verify(zkMock); } private ZKBackend createZKBackend()