List of usage examples for org.apache.zookeeper CreateMode isEphemeral
public boolean isEphemeral()
From source file:org.apache.curator.framework.schema.Schema.java
License:Apache License
/** * Validate that this schema's create mode setting matches and that the data is valid * * @param mode CreateMode being used// w ww . j a va 2 s .c om * @param path the znode full path * @param data data being set * @param acl the creation acls * @throws SchemaViolation if schema's create mode setting does not match or data is invalid */ public void validateCreate(CreateMode mode, String path, byte[] data, List<ACL> acl) { if (mode.isEphemeral() && (ephemeral == Allowance.CANNOT)) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Cannot be ephemeral"); } if (!mode.isEphemeral() && (ephemeral == Allowance.MUST)) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Must be ephemeral"); } if (mode.isSequential() && (sequential == Allowance.CANNOT)) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Cannot be sequential"); } if (!mode.isSequential() && (sequential == Allowance.MUST)) { throw new SchemaViolation(this, new SchemaViolation.ViolatorData(path, data, acl), "Must be sequential"); } validateGeneral(path, data, acl); }
From source file:org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStoreITCase.java
License:Apache License
/** * Tests that {@link CreateMode} is respected. *///from w w w.j a v a 2 s .c om @Test public void testAddWithCreateMode() throws Exception { LongStateStorage longStateStorage = new LongStateStorage(); ZooKeeperStateHandleStore<Long> store = new ZooKeeperStateHandleStore<Long>(ZooKeeper.getClient(), longStateStorage); // Config Long state = 3457347234L; CreateMode[] modes = CreateMode.values(); for (int i = 0; i < modes.length; i++) { CreateMode mode = modes[i]; state += i; String pathInZooKeeper = "/testAddWithCreateMode" + mode.name(); // Test store.add(pathInZooKeeper, state, mode); if (mode.isSequential()) { // Figure out the sequential ID List<String> paths = ZooKeeper.getClient().getChildren().forPath("/"); for (String p : paths) { if (p.startsWith("testAddWithCreateMode" + mode.name())) { pathInZooKeeper = "/" + p; break; } } } // Verify // State handle created assertEquals(i + 1, store.getAll().size()); assertEquals(state, longStateStorage.getStateHandles().get(i).getState(null)); // Path created Stat stat = ZooKeeper.getClient().checkExists().forPath(pathInZooKeeper); assertNotNull(stat); // Is ephemeral or persistent if (mode.isEphemeral()) { assertTrue(stat.getEphemeralOwner() != 0); } else { assertEquals(0, stat.getEphemeralOwner()); } // Data is equal @SuppressWarnings("unchecked") Long actual = ((StateHandle<Long>) InstantiationUtil.deserializeObject( ZooKeeper.getClient().getData().forPath(pathInZooKeeper), ClassLoader.getSystemClassLoader())) .getState(null); assertEquals(state, actual); } }