Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-16614

Calendar get hours of day fetching -1

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Critical
    • 4.1.1
    • 4.5.0
    • query_drivers
    • Security Level: Public
    • None
    • dev
    • Untriaged
    • Unknown

    Description

      Error while running the following test case

      @Test
      public void testSetTime() throws Exception
      {
      Calendar cal = Calendar.getInstance();
      cal.setTimeZone(TimeZone.getTimeZone("America/Toronto"));
      Calendar cal2 = Calendar.getInstance();
      cal2.setTimeZone(TimeZone.getTimeZone("America/Toronto"));

      Time time = new Time(cal.getTime().getTime());

      try(PreparedStatement preparedStatement = con.prepareStatement("insert into default(key,value) values (?,?)"))
      {
      preparedStatement.setString(1,"val1");
      preparedStatement.setTime(2, time);

      assertEquals(1, preparedStatement.executeUpdate());

      preparedStatement.setString(1,"val3");
      preparedStatement.setNull(2, Types.TIME, "time");

      assertEquals(1, preparedStatement.executeUpdate());

      try(Statement statement = con.createStatement())
      {
      try (ResultSet rs = statement.executeQuery("select * from default where meta(default).id='val1'"))

      { assertTrue(rs.next()); Time time1 = rs.getTime("default"); cal2.setTime(time1); assertEquals(cal.get(Calendar.HOUR_OF_DAY),cal2.get(Calendar.HOUR_OF_DAY)); assertEquals(cal.get(Calendar.MINUTE), cal2.get(Calendar.MINUTE)); assertEquals(cal.get(Calendar.SECOND),cal2.get(Calendar.SECOND)); time1 = rs.getTime(1); cal2.setTime(time1); assertEquals(cal.get(Calendar.HOUR_OF_DAY),cal2.get(Calendar.HOUR_OF_DAY)); assertEquals(cal.get(Calendar.MINUTE), cal2.get(Calendar.MINUTE)); assertEquals(cal.get(Calendar.SECOND),cal2.get(Calendar.SECOND)); Calendar differentTimezone = Calendar.getInstance(); differentTimezone.setTimeZone(TimeZone.getTimeZone("GMT")); time1 = rs.getTime(1,differentTimezone); cal2.setTime(time1); int offset = cal2.getTimeZone().getRawOffset()/1000/60/60; assertEquals(cal.get(Calendar.HOUR_OF_DAY), cal2.get(Calendar.HOUR_OF_DAY)+offset); <------ FAILS HERE assertEquals(cal.get(Calendar.MINUTE), cal2.get(Calendar.MINUTE)); assertEquals(cal.get(Calendar.SECOND),cal2.get(Calendar.SECOND)); }

      try (ResultSet rs = statement.executeQuery("select * from default where meta(default).id='val3'"))

      { assertTrue(rs.next()); assertNull( rs.getTime(1)); }

      }

      }
      }

      mvn test -Dtest=com.couchbase.PreparedStatementTest#testSetTime

      Error Observed, returning -1

      junit.framework.AssertionFailedError: expected:<20> but was:<-1>
      at junit.framework.Assert.fail(Assert.java:57)
      at junit.framework.Assert.failNotEquals(Assert.java:329)
      at junit.framework.Assert.assertEquals(Assert.java:78)
      at junit.framework.Assert.assertEquals(Assert.java:234)
      at junit.framework.Assert.assertEquals(Assert.java:241)
      at junit.framework.TestCase.assertEquals(TestCase.java:409)
      at com.couchbase.PreparedStatementTest.testSetTime(PreparedStatementTest.java:772)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
      at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:242)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:137)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
      at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Prerna.Manaktala Prerna Manaktala (Inactive)
              parag Parag Agarwal (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty