// Path: src/main/java/com/imadcn/framework/idworker/generator/SnowflakeGenerator.java
// public class SnowflakeGenerator implements IdGenerator, GeneratorConnector {
// 
//     static final String FIXED_STRING_FORMAT = "%019d";
// 
//     private Logger logger = LoggerFactory.getLogger(getClass());
// 
//     /**
//      * snowflake 算法
//      */
//     private Snowflake snowflake;
//     /**
//      * snowflake 注册
//      */
//     private ZookeeperWorkerRegister register;
//     /**
//      * 是否正在工作
//      */
//     private volatile boolean initialized = false;
// 
//     private volatile boolean working = false;
// 
//     private volatile boolean connecting = false;
// 
//     public SnowflakeGenerator(ZookeeperWorkerRegister register) {
//         this.register = register;
//     }
// 
//     @Override
//     public synchronized void init() {
//         if (!initialized) {
//             // 持久化节点+本地缓存，不再使用状态监听
//             // listener = new ZookeeperConnectionStateListener(this);
//             // // 添加监听
//             // register.addConnectionListener(listener);
//             // 连接与注册workerId
//             connect();
//             initialized = true;
//         }
//     }
// 
//     /**
//      * 初始化
//      */
//     @Override
//     public void connect() {
//         if (!isConnecting()) {
//             working = false;
//             connecting = true;
//             long workerId = register.register();
//             if (workerId >= 0) {
//                 snowflake = Snowflake.create(workerId);
//                 working = true;
//                 connecting = false;
//             } else {
//                 throw new RegException("failed to get worker id");
//             }
//         } else {
//             logger.info("worker is connecting, skip this time of register.");
//         }
//     }
// 
//     @Override
//     public long[] nextId(int size) {
//         if (isWorking()) {
//             return snowflake.nextId(size);
//         }
//         throw new IllegalStateException("worker isn't working, reg center may shutdown");
//     }
// 
//     @Override
//     public long nextId() {
//         if (isWorking()) {
//             return snowflake.nextId();
//         }
//         throw new IllegalStateException("worker isn't working, reg center may shutdown");
//     }
// 
//     @Override
//     public String nextStringId() {
//         return String.valueOf(nextId());
//     }
// 
//     @Override
//     public String nextFixedStringId() {
//         return String.format(FIXED_STRING_FORMAT, nextId());
//     }
// 
//     @Override
//     public void suspend() {
//         this.working = false;
//     }
// 
//     @Override
//     public synchronized void close() throws IOException {
//         // 关闭，先重置状态(避免ZK删除 workerId，其他机器抢注，会导致workerID 重新生成的BUG)
//         reset();
//         register.logout();
//     }
// 
//     @Override
//     public boolean isWorking() {
//         return this.working;
//     }
// 
//     @Override
//     public boolean isConnecting() {
//         return this.connecting;
//     }
// 
//     /**
//      * 重置连接状态
//      */
//     protected void reset() {
//         initialized = false;
//         working = false;
//         connecting = false;
//     }
// 
//     /**
//      * 低并发模式
//      * 
//      * @param lowConcurrency 低并发模式 ? true : false
//      */
//     @Deprecated
//     public void setLowConcurrency(boolean lowConcurrency) {
//     }
// }
// 
// Path: src/test/java/com/imadcn/system/test/spring/AbstractZookeeperJUnit4SpringContextTests.java
// @TestExecutionListeners(EmbedZookeeperTestExecutionListener.class)
// public abstract class AbstractZookeeperJUnit4SpringContextTests extends AbstractJUnit4SpringContextTests {
// 
//     protected Logger logger = LoggerFactory.getLogger(getClass());
// 
//     protected void print(Object object) {
//         String json = JSON.toJSONString(object);
//         System.out.println(json);
//         logger.info(json);
//     }
// }


import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import com.imadcn.framework.idworker.generator.SnowflakeGenerator;
import com.imadcn.system.test.spring.AbstractZookeeperJUnit4SpringContextTests;
/*
 * Copyright 2013-2017 imadcn Group.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.imadcn.system.test.idworker;



@ContextConfiguration(locations = "classpath:META-INF/idworker-ctx-cachable-and-durable.xml")
public final class CachableAndtDurableTest extends AbstractZookeeperJUnit4SpringContextTests {

    @Autowired
    private SnowflakeGenerator snowflakeGenerator;

// Path: src/main/java/com/imadcn/framework/idworker/generator/SnowflakeGenerator.java
// public class SnowflakeGenerator implements IdGenerator, GeneratorConnector {
// 
//     static final String FIXED_STRING_FORMAT = "%019d";
// 
//     private Logger logger = LoggerFactory.getLogger(getClass());
// 
//     /**
//      * snowflake 算法
//      */
//     private Snowflake snowflake;
//     /**
//      * snowflake 注册
//      */
//     private ZookeeperWorkerRegister register;
//     /**
//      * 是否正在工作
//      */
//     private volatile boolean initialized = false;
// 
//     private volatile boolean working = false;
// 
//     private volatile boolean connecting = false;
// 
//     public SnowflakeGenerator(ZookeeperWorkerRegister register) {
//         this.register = register;
//     }
// 
//     @Override
//     public synchronized void init() {
//         if (!initialized) {
//             // 持久化节点+本地缓存，不再使用状态监听
//             // listener = new ZookeeperConnectionStateListener(this);
//             // // 添加监听
//             // register.addConnectionListener(listener);
//             // 连接与注册workerId
//             connect();
//             initialized = true;
//         }
//     }
// 
//     /**
//      * 初始化
//      */
//     @Override
//     public void connect() {
//         if (!isConnecting()) {
//             working = false;
//             connecting = true;
//             long workerId = register.register();
//             if (workerId >= 0) {
//                 snowflake = Snowflake.create(workerId);
//                 working = true;
//                 connecting = false;
//             } else {
//                 throw new RegException("failed to get worker id");
//             }
//         } else {
//             logger.info("worker is connecting, skip this time of register.");
//         }
//     }
// 
//     @Override
//     public long[] nextId(int size) {
//         if (isWorking()) {
//             return snowflake.nextId(size);
//         }
//         throw new IllegalStateException("worker isn't working, reg center may shutdown");
//     }
// 
//     @Override
//     public long nextId() {
//         if (isWorking()) {
//             return snowflake.nextId();
//         }
//         throw new IllegalStateException("worker isn't working, reg center may shutdown");
//     }
// 
//     @Override
//     public String nextStringId() {
//         return String.valueOf(nextId());
//     }
// 
//     @Override
//     public String nextFixedStringId() {
//         return String.format(FIXED_STRING_FORMAT, nextId());
//     }
// 
//     @Override
//     public void suspend() {
//         this.working = false;
//     }
// 
//     @Override
//     public synchronized void close() throws IOException {
//         // 关闭，先重置状态(避免ZK删除 workerId，其他机器抢注，会导致workerID 重新生成的BUG)
//         reset();
//         register.logout();
//     }
// 
//     @Override
//     public boolean isWorking() {
//         return this.working;
//     }
// 
//     @Override
//     public boolean isConnecting() {
//         return this.connecting;
//     }
// 
//     /**
//      * 重置连接状态
//      */
//     protected void reset() {
//         initialized = false;
//         working = false;
//         connecting = false;
//     }
// 
//     /**
//      * 低并发模式
//      * 
//      * @param lowConcurrency 低并发模式 ? true : false
//      */
//     @Deprecated
//     public void setLowConcurrency(boolean lowConcurrency) {
//     }
// }
// 
// Path: src/test/java/com/imadcn/system/test/spring/AbstractZookeeperJUnit4SpringContextTests.java
// @TestExecutionListeners(EmbedZookeeperTestExecutionListener.class)
// public abstract class AbstractZookeeperJUnit4SpringContextTests extends AbstractJUnit4SpringContextTests {
// 
//     protected Logger logger = LoggerFactory.getLogger(getClass());
// 
//     protected void print(Object object) {
//         String json = JSON.toJSONString(object);
//         System.out.println(json);
//         logger.info(json);
//     }
// }


// Path: src/test/java/com/imadcn/system/test/idworker/CachableAndtDurableTest.java
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import com.imadcn.framework.idworker.generator.SnowflakeGenerator;
import com.imadcn.system.test.spring.AbstractZookeeperJUnit4SpringContextTests;

/*
 * Copyright 2013-2017 imadcn Group.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package com.imadcn.system.test.idworker;



@ContextConfiguration(locations = "classpath:META-INF/idworker-ctx-cachable-and-durable.xml")
public final class CachableAndtDurableTest extends AbstractZookeeperJUnit4SpringContextTests {

    @Autowired
    private SnowflakeGenerator snowflakeGenerator;

    @Test