Package org.apache.flink.types

Examples of org.apache.flink.types.StringValue


  }

  @Test
  public void testPactMap() {
    NfIntStringMap map0 = new NfIntStringMap();
    map0.put(new IntValue(10), new StringValue("20"));

    // test data retrieval
    for (Entry<IntValue, StringValue> entry : map0.entrySet()) {
      Assert.assertEquals(entry.getValue(), new StringValue("20"));
      Assert.assertEquals(entry.getKey(), new IntValue(10));
    }

    // test data overwriting
    map0.put(new IntValue(10), new StringValue("10"));
    for (Entry<IntValue, StringValue> entry : map0.entrySet()) {
      Assert.assertEquals(entry.getValue(), new StringValue("10"));
      Assert.assertEquals(entry.getKey(), new IntValue(10));
    }

    // now test data retrieval of multiple values
    map0.put(new IntValue(20), new StringValue("20"));
    map0.put(new IntValue(30), new StringValue("30"));
    map0.put(new IntValue(40), new StringValue("40"));

    // construct an inverted map
    NfStringIntMap mapinv = new NfStringIntMap();
    for (Entry<IntValue, StringValue> entry : map0.entrySet()) {
      Assert.assertEquals(entry.getKey().getValue(), Integer.parseInt(entry.getValue().toString()));
View Full Code Here


  }

  @Test
  public void testPactList() {
    NfStringList list = new NfStringList();
    list.add(new StringValue("Hello!"));

    for (StringValue value : list) {
      Assert.assertEquals(value, new StringValue("Hello!"));
    }

    list.add(new StringValue("Hello2!"));
    list.add(new StringValue("Hello3!"));
    list.add(new StringValue("Hello4!"));

    Assert.assertTrue(list.equals(list));

    // test data transfer
    NfStringList mList2 = new NfStringList();
View Full Code Here

    }
  }

  @Test
  public void testStringValue() {
    StringValue string0 = new StringValue("This is a test");
    StringValue stringThis = new StringValue("This");
    StringValue stringIsA = new StringValue("is a");
    // test value retrieval
    Assert.assertEquals("This is a test", string0.toString());
    // test value comparison
    StringValue string1 = new StringValue("This is a test");
    StringValue string2 = new StringValue("This is a tesa");
    StringValue string3 = new StringValue("This is a tesz");
    StringValue string4 = new StringValue("Ünlaut ßtring ยต avec é y ¢");
    CharSequence chars5 = string1.subSequence(0, 4);
    StringValue string5 = (StringValue) chars5;
    StringValue string6 = (StringValue) string0.subSequence(0, string0.length());
    StringValue string7 = (StringValue) string0.subSequence(5, 9);
    StringValue string8 = (StringValue) string0.subSequence(0, 0);
    Assert.assertTrue(string0.compareTo(string0) == 0);
    Assert.assertTrue(string0.compareTo(string1) == 0);
    Assert.assertTrue(string0.compareTo(string2) > 0);
    Assert.assertTrue(string0.compareTo(string3) < 0);
    Assert.assertTrue(stringThis.equals(chars5));
    Assert.assertTrue(stringThis.compareTo(string5) == 0);
    Assert.assertTrue(string0.compareTo(string6) == 0);
    Assert.assertTrue(stringIsA.compareTo(string7) == 0);
    string7.setValue("This is a test");
    Assert.assertTrue(stringIsA.compareTo(string7) > 0);
    Assert.assertTrue(string0.compareTo(string7) == 0);
    string7.setValue("is a");
    Assert.assertTrue(stringIsA.compareTo(string7) == 0);
    Assert.assertTrue(string0.compareTo(string7) < 0);
    Assert.assertEquals(stringIsA.hashCode(), string7.hashCode());
    Assert.assertEquals(string7.length(), 4);
    Assert.assertEquals("is a", string7.getValue());
    Assert.assertEquals(string8.length(), 0);
    Assert.assertEquals("", string8.getValue());
    Assert.assertEquals('s', string7.charAt(1));
    try {
      string7.charAt(5);
      Assert.fail("Exception should have been thrown when accessing characters out of bounds.");
    } catch (IndexOutOfBoundsException iOOBE) {}
   
    // test stream out/input
    try {
      string0.write(new OutputViewDataOutputStreamWrapper(mOut));
      string4.write(new OutputViewDataOutputStreamWrapper(mOut));
      string2.write(new OutputViewDataOutputStreamWrapper(mOut));
      string3.write(new OutputViewDataOutputStreamWrapper(mOut));
      string7.write(new OutputViewDataOutputStreamWrapper(mOut));
      StringValue string1n = new StringValue();
      StringValue string2n = new StringValue();
      StringValue string3n = new StringValue();
      StringValue string4n = new StringValue();
      StringValue string7n = new StringValue();
      string1n.read(new InputViewDataInputStreamWrapper(mIn));
      string4n.read(new InputViewDataInputStreamWrapper(mIn));
      string2n.read(new InputViewDataInputStreamWrapper(mIn));
      string3n.read(new InputViewDataInputStreamWrapper(mIn));
      string7n.read(new InputViewDataInputStreamWrapper(mIn));
      Assert.assertEquals(string0.compareTo(string1n), 0);
      Assert.assertEquals(string0.toString(), string1n.toString());
      Assert.assertEquals(string4.compareTo(string4n), 0);
      Assert.assertEquals(string4.toString(), string4n.toString());
      Assert.assertEquals(string2.compareTo(string2n), 0);
      Assert.assertEquals(string2.toString(), string2n.toString());
      Assert.assertEquals(string3.compareTo(string3n), 0);
      Assert.assertEquals(string3.toString(), string3n.toString());
      Assert.assertEquals(string7.compareTo(string7n), 0);
      Assert.assertEquals(string7.toString(), string7n.toString());
      try {
        string7n.charAt(5);
        Assert.fail("Exception should have been thrown when accessing characters out of bounds.");
      } catch (IndexOutOfBoundsException iOOBE) {}
     
    } catch (Exception e) {
      Assert.assertTrue(false);
View Full Code Here

public class InstantiationUtilsTest {

  @Test
  public void testInstatiationOfStringValue() {
    StringValue stringValue = InstantiationUtil.instantiate(
        StringValue.class, null);
    assertNotNull(stringValue);
  }
View Full Code Here

    assertNotNull(stringValue);
  }

  @Test
  public void testInstatiationOfStringValueAndCastToValue() {
    StringValue stringValue = InstantiationUtil.instantiate(
        StringValue.class, Value.class);
    assertNotNull(stringValue);
  }
View Full Code Here

      Assert.fail();
    }
   
    // check incorrect key types
    try {
      new SimpleDistribution(new Key[] {new IntValue(1), new StringValue("ABC"), new IntValue(3)});
      Assert.fail("Data distribution accepts inconsistent key types");
    } catch(IllegalArgumentException iae) {
      // do nothing
    }
   
View Full Code Here

  @Test
  public void testConstructorMultiKey() {
   
    // check correct data distribution
    SimpleDistribution dd = new SimpleDistribution(
        new Key[][] {{new IntValue(1), new StringValue("A"), new IntValue(1)},
              {new IntValue(2), new StringValue("A"), new IntValue(1)},
              {new IntValue(3), new StringValue("A"), new IntValue(1)}});
    Assert.assertEquals(3, dd.getNumberOfFields());
   
    // check inconsistent key types
    try {
      new SimpleDistribution(
          new Key[][] {{new IntValue(1), new StringValue("A"), new DoubleValue(1.3d)},
                {new IntValue(2), new StringValue("B"), new IntValue(1)}});
      Assert.fail("Data distribution accepts incorrect key types");
    } catch(IllegalArgumentException iae) {
      // do nothing
    }
   
View Full Code Here

 
  @Test
  public void testWriteRead() {
   
    SimpleDistribution ddWrite = new SimpleDistribution(
        new Key[][] {{new IntValue(1), new StringValue("A"), new IntValue(1)},
              {new IntValue(2), new StringValue("A"), new IntValue(1)},
              {new IntValue(2), new StringValue("B"), new IntValue(4)},
              {new IntValue(2), new StringValue("B"), new IntValue(3)},
              {new IntValue(2), new StringValue("B"), new IntValue(2)}});
    Assert.assertEquals(3, ddWrite.getNumberOfFields());
   
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final DataOutputStream dos = new DataOutputStream(baos);
    try {
View Full Code Here

 
  @Test
  public void testGetBucketBoundary() {
   
    SimpleDistribution dd = new SimpleDistribution(
        new Key[][] {{new IntValue(1), new StringValue("A")},
              {new IntValue(2), new StringValue("B")},
              {new IntValue(3), new StringValue("C")},
              {new IntValue(4), new StringValue("D")},
              {new IntValue(5), new StringValue("E")},
              {new IntValue(6), new StringValue("F")},
              {new IntValue(7), new StringValue("G")}});
   
    Key<?>[] boundRec = dd.getBucketBoundary(0, 8);
    Assert.assertEquals(((IntValue) boundRec[0]).getValue(), 1);
    Assert.assertTrue(((StringValue) boundRec[1]).getValue().equals("A"));
   
View Full Code Here

public class SimpleStringUtilsTest {

  @Test
  public void testToLowerCaseConverting() {
    StringValue testString = new StringValue("TEST");
    SimpleStringUtils.toLowerCase(testString);
    assertEquals(new StringValue("test"), testString);
  }
View Full Code Here

TOP

Related Classes of org.apache.flink.types.StringValue

Copyright © 2018 www.massapicom. 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.