Java Code Examples for org.apache.brooklyn.util.time.Time#makeDateString()

The following examples show how to use org.apache.brooklyn.util.time.Time#makeDateString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLoadBalancingPolicyTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected String verboseDumpToString(Iterable<MockContainerEntity> containers, Iterable<? extends Movable> items) {
    Iterable<Double> containerRates = Iterables.transform(containers, new Function<MockContainerEntity, Double>() {
        @Override public Double apply(MockContainerEntity input) {
            return (double) input.getWorkrate();
        }});
    
    Map<MockContainerEntity, Set<Movable>> itemDistributionByContainer = Maps.newLinkedHashMap();
    for (MockContainerEntity container : containers) {
        itemDistributionByContainer.put(container, container.getBalanceableItems());
    }
    
    Map<Movable, BalanceableContainer<?>> itemDistributionByItem = Maps.newLinkedHashMap();
    for (Movable item : items) {
        itemDistributionByItem.put(item, item.getAttribute(Movable.CONTAINER));
    }

    String modelItemDistribution = model.itemDistributionToString();
    return "containers="+containers+"; containerRates="+containerRates
            +"; itemDistributionByContainer="+itemDistributionByContainer
            +"; itemDistributionByItem="+itemDistributionByItem
            +"; model="+modelItemDistribution
            +"; totalMoves="+MockItemEntityImpl.totalMoveCount
            +"; lastMoveTime="+Time.makeDateString(MockItemEntityImpl.lastMoveTime.get());
}
 
Example 2
Source File: MiscClassesRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/** Method to facilitate creation of memento files */
private void createMemento() throws Exception {
    setUp();
    origApp = super.createApp();
    
    // edit this, run this class's main method, then use the log output for your test case
    origApp.config().set(TEST_KEY,  new VersionedName("foo", Version.parseVersion("1.0.0.foo")));

    
    RebindTestUtils.stopPersistence(origApp);
    String fn = mementoDir + File.separator + "entities" + File.separator + origApp.getApplicationId();
    log.info("Persisted to "+fn);
    String yyyyMM = Time.makeDateString(new Date(), "yyyy-MM");
    log.info("Set up your tests by copying from the persistence dir "+mementoDir+"\n\n"+
        "cp "+fn+" "+
        "src/test/resources/"+getClass().getPackage().getName().replaceAll("\\.", "/")+"/"+
        JavaClassNames.cleanSimpleClassName(this)+"-"+yyyyMM+"-entity-"+origApp.getApplicationId()+".memento\n");
    String content = Streams.readFullyString(new FileInputStream(new File(fn)));
    log.info("Or paste the following contents there:\n"+content);
    log.info("Then add the apache comment header there, and write your test doing  loadEntityMemento(\""+yyyyMM+"\", \""+origApp.getApplicationId()+"\")");
}
 
Example 3
Source File: JmxHelper.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a usable MBeanServerConnection.
 *
 * Method is threadsafe.
 *
 * @returns the MBeanServerConnection
 * @throws IllegalStateException if not connected.
 */
private synchronized MBeanServerConnection getConnectionOrFail() {
    if (isConnected())
        return getConnection();

    if (triedConnecting) {
        throw new IllegalStateException("Failed to connect to JMX at "+url);
    } else {
        String msg = "Not connected (and not attempted to connect) to JMX at "+url+
                (failedReconnecting ? (" (last reconnect failure at "+ Time.makeDateString(failedReconnectingTime) + ")") : "");
        throw new IllegalStateException(msg);
    }
}
 
Example 4
Source File: UsageResourceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void assertAppUsageTimesTruncated(UsageStatistics usages, Calendar strictStart, Calendar strictEnd) throws Exception {
    String errMsg = "strictStart="+Time.makeDateString(strictStart)+"; strictEnd="+Time.makeDateString(strictEnd)+";usages="+usages;
    Calendar usageStart = Time.parseCalendar(Iterables.getFirst(usages.getStatistics(), null).getStart());
    Calendar usageEnd = Time.parseCalendar(Iterables.getLast(usages.getStatistics()).getStart());
    // time zones might be different - so must convert to date
    assertEquals(usageStart.getTime(), strictStart.getTime(), "usageStart="+Time.makeDateString(usageStart)+";"+errMsg);
    assertEquals(usageEnd.getTime(), strictEnd.getTime(), errMsg);
}
 
Example 5
Source File: UsageResource.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
private String format(Date date) {
    return Time.makeDateString(date, Time.DATE_FORMAT_ISO8601_NO_MILLIS, Time.TIME_ZONE_UTC);
}