Examples of Storage


Examples of lesson07.storage.Storage

public class Test {
    private static String url = "jdbc:mysql://localhost:3306/";
    public static void main(String[] args) throws Exception {
        Connection connection = createConnection("test", "root", "geekdb");

        Storage storage = new DatabaseStorage(connection);
        List<Cat> cats = storage.list(Cat.class);
        for (Cat cat : cats) {
            storage.delete(cat);
        }
        cats = storage.list(Cat.class);
        if (!cats.isEmpty()) throw new Exception("Cats should not be in database!");

        for(int i = 1; i <= 20; i++) {
            Cat cat = new Cat();
            cat.setName("cat" + i);
            cat.setAge(i);
            storage.save(cat);
        }

        cats = storage.list(Cat.class);
        if (cats.size() != 20) throw new Exception("Number of cats in storage should be 20!");

        User user = new User();
        user.setAdmin(true);
        user.setAge(23);
        user.setName("Victor");
        user.setBalance(22.23);
        storage.save(user);

        User user1 = storage.get(User.class, user.getId());
        if (!user1.getName().equals(user.getName())) throw new Exception("Users should be equals!");

        user.setAdmin(false);
        storage.save(user);

        User user2 = storage.get(User.class, user.getId());
        if (!user.getAdmin().equals(user2.getAdmin())) throw new Exception("Users should be updated!");

        storage.delete(user1);

        User user3 = storage.get(User.class, user.getId());

        if (user3 != null) throw new Exception("User should be deleted!");

        connection.close();
    }
View Full Code Here

Examples of lesson7.storage.Storage

public class Test {
    public static void main(String[] args) throws Exception {
        Connection connection = createConnection("root", "root", "jdbc:mysql://localhost/geekdb");

        Storage storage = new DatabaseStorage(connection);
        List<Cat> cats = storage.list(Cat.class);
        for (Cat cat : cats) {
            storage.delete(cat);
        }
        cats = storage.list(Cat.class);
        if (!cats.isEmpty()) throw new Exception("Cats should not be in database!");

        for(int i = 1; i <= 20; i++) {
            Cat cat = new Cat();
            cat.setName("cat" + i);
            cat.setAge(i);
            storage.save(cat);
        }

        cats = storage.list(Cat.class);
        if (cats.size() != 20) throw new Exception("Number of cats in storage should be 20!");

        User user = new User();
        user.setAdmin(true);
        user.setAge(23);
        user.setName("Victor");
        user.setBalance(22.23);
        user.setId(29);
        storage.save(user);

        User user1 = storage.get(User.class, user.getId());
        if (!user1.getName().equals(user.getName())) throw new Exception("Users should be equals!");

        user.setAdmin(false);
        storage.save(user);
        User user2 = storage.get(User.class, user.getId());
        if (!user.getAdmin().equals(user2.getAdmin())) throw new Exception("Users should be updated!");

        storage.delete(user1);

        User user3 = storage.get(User.class, user.getId());

        if (user3 != null) throw new Exception("User should be deleted!");

        connection.close();
    }
View Full Code Here

Examples of mindnotes.client.storage.Storage

    NodeView childView = nodeView.createChild();
    setUpNodeView(childView, newNode);
  }

  public void load(final MindMapInfo map, boolean local) {
    Storage s = local ? getLocalStorage() : getCloudStorage();
    s.loadMindMap(map, new AsyncCallback<MindMap>() {

      @Override
      public void onFailure(Throwable caught) {

        if (caught instanceof InvocationException) {
View Full Code Here

Examples of net.citizensnpcs.properties.Storage

    public static void clearGlobal() {
        globalStock.clear();
    }

    public static void loadGlobal() {
        Storage storage = UtilityProperties.getConfig();
        for (Object key : storage.getKeys("traders.global-prices")) {
            String path = "traders.global-prices." + key;
            int itemID = storage.getInt(path + ".id", 1);
            int amount = storage.getInt(path + ".amount", 1);
            short data = (short) storage.getInt(path + ".data");
            double price = storage.getDouble(path + ".price");
            boolean selling = !storage.getBoolean(path + ".selling", false);
            if (itemID > 0 && amount > 0) {
                Stockable stock = new Stockable(new ItemStack(itemID, amount, data), new ItemPrice(price), selling);
                globalStock.put(stock.createCheck(), stock);
            }
        }
View Full Code Here

Examples of net.tomp2p.storage.Storage

      return new StorageMemory();
    }

    @Test
    public void testPutInitial() throws Exception {
        Storage storageM = createStorage();
        store(new StorageLayer(storageM));
        storageM.close();
    }
View Full Code Here

Examples of org.apache.ambari.view.pig.persistence.Storage

    expect(context.getProperties()).andReturn(properties).anyTimes();
    expect(context.getUsername()).andReturn("ambari-qa").anyTimes();

    replay(handler, context);

    Storage storage = StorageUtil.getStorage(context);
    Assert.assertEquals(InstanceKeyValueStorage.class.getSimpleName(), storage.getClass().getSimpleName());
  }
View Full Code Here

Examples of org.apache.aurora.scheduler.storage.Storage

  public static Storage newEmptyStorage() {
    Injector injector = Guice.createInjector(
        DbModule.testModule(Bindings.annotatedKeyFactory(Delegated.class)),
        new MemStorageModule(Bindings.annotatedKeyFactory(Volatile.class)));

    Storage storage = injector.getInstance(Key.get(Storage.class, Volatile.class));
    storage.prepare();
    return storage;
  }
View Full Code Here

Examples of org.apache.aurora.scheduler.storage.Storage

  @Test
  public void testIgnoresThrottledTasks() throws Exception {
    // Ensures that tasks in THROTTLED state are not considered part of the active job state passed
    // to the assigner function.

    Storage memStorage = MemStorage.newEmptyStorage();

    Injector injector = getInjector(memStorage);
    scheduler = injector.getInstance(TaskScheduler.class);
    eventSink = PubsubTestUtil.startPubsub(injector);

    ScheduledTask builder = TASK_A.newBuilder();
    final IScheduledTask taskA = IScheduledTask.build(builder.setStatus(PENDING));
    builder.getAssignedTask().setTaskId("b");
    final IScheduledTask taskB = IScheduledTask.build(builder.setStatus(THROTTLED));

    memStorage.write(new MutateWork.NoResult.Quiet() {
      @Override
      protected void execute(MutableStoreProvider store) {
        store.getUnsafeTaskStore().saveTasks(ImmutableSet.of(taskA, taskB));
      }
    });
View Full Code Here

Examples of org.apache.aurora.scheduler.storage.Storage

  @Test
  public void testIgnoresThrottledTasks() throws Exception {
    // Ensures that the preemptor does not consider a throttled task to be a preemption candidate.
    schedulingFilter = createMock(SchedulingFilter.class);

    Storage storage = MemStorage.newEmptyStorage();

    final ScheduledTask throttled = makeTask(USER_A, JOB_A, TASK_ID_A + "_a1").setStatus(THROTTLED);
    throttled.getAssignedTask().getTask().setNumCpus(1).setRamMb(512);

    final ScheduledTask pending = makeProductionTask(USER_B, JOB_B, TASK_ID_B + "_p1");
    pending.getAssignedTask().getTask().setNumCpus(1).setRamMb(1024);

    storage.write(new MutateWork.NoResult.Quiet() {
      @Override
      protected void execute(MutableStoreProvider store) {
        store.getUnsafeTaskStore().saveTasks(ImmutableSet.of(
            IScheduledTask.build(pending),
            IScheduledTask.build(throttled)));
View Full Code Here

Examples of org.apache.aurora.scheduler.storage.Storage

   * A factory that creates temporary storage instances, detached from the rest of the system.
   */
  class TemporaryStorageFactory implements Function<Snapshot, TemporaryStorage> {
    @Override
    public TemporaryStorage apply(Snapshot snapshot) {
      final Storage storage = MemStorage.newEmptyStorage();
      FakeClock clock = new FakeClock();
      clock.setNowMillis(snapshot.getTimestamp());
      final SnapshotStore<Snapshot> snapshotStore = new SnapshotStoreImpl(clock, storage);
      snapshotStore.applySnapshot(snapshot);

      return new TemporaryStorage() {
        @Override
        public void deleteTasks(final Query.Builder query) {
          storage.write(new MutateWork.NoResult.Quiet() {
            @Override
            protected void execute(MutableStoreProvider storeProvider) {
              Set<String> ids = FluentIterable.from(storeProvider.getTaskStore().fetchTasks(query))
                  .transform(Tasks.SCHEDULED_TO_ID)
                  .toSet();
              storeProvider.getUnsafeTaskStore().deleteTasks(ids);
            }
          });
        }

        @Override
        public Set<IScheduledTask> fetchTasks(final Query.Builder query) {
          return storage.consistentRead(new Work.Quiet<Set<IScheduledTask>>() {
            @Override
            public Set<IScheduledTask> apply(StoreProvider storeProvider) {
              return storeProvider.getTaskStore().fetchTasks(query);
            }
          });
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.