You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2015/11/15 06:02:28 UTC

[1/5] thrift git commit: THRIFT-3425 Minor fixes + simplification for CentOS Dockerfile Client: Build Patch: Nobuaki Sukegawa

Repository: thrift
Updated Branches:
  refs/heads/master f892674d1 -> a8c74d5c5


THRIFT-3425 Minor fixes + simplification for CentOS Dockerfile
Client: Build
Patch: Nobuaki Sukegawa

This closes #699


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/a8c74d5c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/a8c74d5c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/a8c74d5c

Branch: refs/heads/master
Commit: a8c74d5c521faa333e6b70445c08f94dec6b53c1
Parents: 6defea5
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Tue Nov 10 16:37:52 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Nov 15 14:00:18 2015 +0900

----------------------------------------------------------------------
 build/docker/centos/Dockerfile | 45 +++++++++----------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/a8c74d5c/build/docker/centos/Dockerfile
----------------------------------------------------------------------
diff --git a/build/docker/centos/Dockerfile b/build/docker/centos/Dockerfile
index 2ba73c3..95601db 100644
--- a/build/docker/centos/Dockerfile
+++ b/build/docker/centos/Dockerfile
@@ -23,44 +23,28 @@ MAINTAINER Apache Thrift <de...@thrift.apache.org>
 
 ENV HOME /root
 
-# RUN yum -y update
-
 # General dependencies
-RUN yum -y install -y tar m4 perl gcc git libtool zlib-devel openssl-devel autoconf make bison bison-devel flex
-
-RUN mkdir -p /tmp/epel && \
-    curl -sSL "http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm" -o /tmp/epel/epel-release-7-5.noarch.rpm && \
-    cd /tmp/epel && \
-    rpm -ivh epel-release*.rpm && \
-    cd $HOME
-
-# Automake
-RUN mkdir -p /tmp/automake && \
-    curl -SL "http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz" | tar -xzC /tmp/automake && \
-    cd /tmp/automake/automake-1.14 && \
-    ./configure --prefix=/usr && \
-    make && \
-    make install && \
-    cd $HOME
+RUN yum install -y tar m4 perl gcc gcc-c++ git libtool zlib-devel openssl-devel autoconf make bison bison-devel flex epel-release
 
 # C++ dependencies
-RUN yum install -y libboost-dev libevent-devel
+RUN yum install -y boost-devel-static libevent-devel
 
 # Java Dependencies
-RUN yum install -y ant junit ant-nodeps ant-junit java-1.7.0-openjdk-devel
+RUN yum install -y ant junit ant-junit java-1.7.0-openjdk-devel
 
 # Python Dependencies
-RUN yum install -y python-devel python-setuptools python-twisted python-six
+RUN yum install -y python-devel python-setuptools python-twisted-web python-six
 
 # Ruby Dependencies
 RUN yum install -y ruby ruby-devel rubygems && \
     gem install bundler rake
 
 # Perl Dependencies
-RUN yum install -y perl-Bit-Vector perl-Class-Accessor perl-ExtUtils-MakeMaker perl-Test-Simple
+RUN yum install -y perl-Bit-Vector perl-Class-Accessor perl-ExtUtils-MakeMaker perl-Test-Simple \
+    perl-IO-Socket-SSL perl-Net-SSLeay perl-Crypt-SSLeay
 
 # PHP Dependencies
-RUN yum install -y php php-devel php-pear re2c
+RUN yum install -y php php-devel php-pear re2c php-phpunit-PHPUnit bzip2
 
 # GLibC Dependencies
 RUN yum install -y glib2-devel
@@ -70,24 +54,17 @@ RUN curl -sSL http://packages.erlang-solutions.com/rpm/centos/erlang_solutions.r
     yum install -y erlang-kernel erlang-erts erlang-stdlib erlang-eunit erlang-rebar erlang-tools
 
 # Go Dependencies
-RUN curl -sSL https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | tar -C /usr/lib/ -xz && \
-    mkdir -p /usr/share/go
-
-ENV GOROOT /usr/lib/go
-ENV GOPATH /usr/share/go
-ENV PATH ${GOROOT}/bin:${GOPATH}/bin:$PATH
+RUN curl -sSL https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
+ENV PATH /usr/local/go/bin:$PATH
 
 # Haskell Dependencies
-RUN yum -y install cabal-dev && \
-    cabal update && \
-    cabal install cabal-install && \
-    cd $HOME
+RUN yum -y install haskell-platform
 
 # Node.js Dependencies
 RUN yum install -y nodejs nodejs-devel npm
 
 # C# Dependencies
-RUN yum install -y mono-core mono-devel mono-web-devel mono-extras mingw32-binutils mingw32-runtime mingw32-nsis
+RUN yum install -y mono-core mono-devel mono-web-devel mono-extras mingw32-binutils mingw32-crt mingw32-nsis
 
 # Clean up
 RUN rm -rf /tmp/* && \


[4/5] thrift git commit: THRIFT-3200 JS and nodejs do not encode JSON protocol binary fields as base64 Client: Javascript Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3200 JS and nodejs do not encode JSON protocol binary fields as base64
Client: Javascript
Patch: Nobuaki Sukegawa

This closes #698


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/6defea5f
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/6defea5f
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/6defea5f

Branch: refs/heads/master
Commit: 6defea5f7b22ed539ad136ddd3ca09fc8352fffd
Parents: bc7e480
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sat Nov 14 17:36:29 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Nov 15 14:00:18 2015 +0900

----------------------------------------------------------------------
 lib/js/Gruntfile.js           |   6 +-
 lib/js/src/thrift.js          |  19 +-
 lib/js/test/phantom-client.js | 382 +++++++++++++++++++++++++++++++++++++
 lib/js/test/test.js           |  20 +-
 test/tests.json               |  19 ++
 5 files changed, 439 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/6defea5f/lib/js/Gruntfile.js
----------------------------------------------------------------------
diff --git a/lib/js/Gruntfile.js b/lib/js/Gruntfile.js
index 32c8834..ae3783b 100644
--- a/lib/js/Gruntfile.js
+++ b/lib/js/Gruntfile.js
@@ -41,7 +41,7 @@ module.exports = function(grunt) {
         command: 'mkdir test/build; mkdir test/build/js; cp src/thrift.js test/build/js/thrift.js'
       },
       InstallThriftNodeJSDep: {
-        command: 'cd ../nodejs; npm install'
+        command: 'cd ../..; npm install'
       },
       ThriftGen: {
         command: 'thrift -gen js -gen js:node -o test ../../test/ThriftTest.thrift'
@@ -61,7 +61,7 @@ module.exports = function(grunt) {
           },
           nodeSpawnOptions: {
                               cwd: "test",
-                              env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
+                              env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
                             }
         },
         cmd: "node",
@@ -74,7 +74,7 @@ module.exports = function(grunt) {
           },
           nodeSpawnOptions: {
                               cwd: "test",
-                              env: {NODE_PATH: "../../nodejs/lib:../../nodejs/node_modules"}
+                              env: {NODE_PATH: "../../nodejs/lib:../../../node_modules"}
                             }
         },
         cmd: "node",

http://git-wip-us.apache.org/repos/asf/thrift/blob/6defea5f/lib/js/src/thrift.js
----------------------------------------------------------------------
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index 9bd1198..664171e 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -1006,8 +1006,19 @@ Thrift.Protocol.prototype = {
     },
 
     /** Serializes a string */
-    writeBinary: function(str) {
-        this.writeString(str);
+    writeBinary: function(binary) {
+        var str = '';
+        if (typeof binary == 'string') {
+            str = binary;
+        } else if (binary instanceof Uint8Array) {
+            var arr = binary;
+            for (var i = 0; i < arr.length; ++i) {
+                str += String.fromCharCode(arr[i]);
+            }
+        } else {
+            throw new TypeError('writeBinary only accepts String or Uint8Array.');
+        }
+        this.tstack.push('"' + btoa(str) + '"');
     },
 
     /**
@@ -1309,7 +1320,9 @@ Thrift.Protocol.prototype = {
     /** Returns the an object with a value property set to the 
         next value found in the protocol buffer */
     readBinary: function() {
-        return this.readString();
+        var r = this.readI32();
+        r.value = atob(r.value);
+        return r;
     },
 
     /** 

http://git-wip-us.apache.org/repos/asf/thrift/blob/6defea5f/lib/js/test/phantom-client.js
----------------------------------------------------------------------
diff --git a/lib/js/test/phantom-client.js b/lib/js/test/phantom-client.js
new file mode 100644
index 0000000..f75b256
--- /dev/null
+++ b/lib/js/test/phantom-client.js
@@ -0,0 +1,382 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+ /* jshint -W100 */
+
+(function() {
+  'use strict';
+
+  // Rudimentary test helper functions
+  // TODO: Return error code based on kind of errors rather than throw
+  var ok = function(t, msg) {
+    if (!t) {
+      console.log('*** FAILED ***');
+      throw new Error(msg);
+    }
+  };
+  var equal = function(a, b) {
+    if (a !== b) {
+      console.log('*** FAILED ***');
+      throw new Error();
+    }
+  };
+  var test = function(name, f) {
+    console.log('TEST : ' + name);
+    f();
+    console.log('OK\n');
+  };
+
+  var parseArgs = function(args) {
+    var skips = [
+      '--transport=http',
+      '--protocol=json',
+    ];
+    var opts = {
+      port: '9090',
+      // protocol: 'json',
+    };
+    var keys = {};
+    for (var key in opts) {
+      keys['--' + key + '='] = key;
+    }
+    for (var i in args) {
+      var arg = args[i];
+      if (skips.indexOf(arg) != -1) {
+        continue;
+      }
+      var hit = false;
+      for (var k in keys) {
+        if (arg.slice(0, k.length) === k) {
+          opts[keys[k]] = arg.slice(k.length);
+          hit = true;
+          break;
+        }
+      }
+      if (!hit) {
+        throw new Error('Unknown argument: ' + arg);
+      }
+    }
+    opts.port = parseInt(opts.port, 10);
+    if (!opts.port || opts.port < 1 || opts.port > 65535) {
+      throw new Error('Invalid port number');
+    }
+    return opts;
+  };
+
+  var execute = function() {
+    console.log('### Apache Thrift Javascript standalone test client');
+    console.log('------------------------------------------------------------');
+
+    phantom.page.injectJs('src/thrift.js');
+    phantom.page.injectJs('test/gen-js/ThriftTest_types.js');
+    phantom.page.injectJs('test/gen-js/ThriftTest.js');
+
+    var system = require('system');
+    var opts = parseArgs(system.args.slice(1));
+    var port = opts.port;
+    var transport = new Thrift.Transport('http://localhost:' + port + '/service');
+    var protocol  = new Thrift.Protocol(transport);
+    var client    = new ThriftTest.ThriftTestClient(protocol);
+
+
+    // TODO: Remove duplicate code with test.js.
+    // all Languages in UTF-8
+    var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къа
 рачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中�
 �, Bân-lâm-gú, 粵語";
+
+    function checkRecursively(map1, map2) {
+      if (typeof map1 !== 'function' && typeof map2 !== 'function') {
+        if (!map1 || typeof map1 !== 'object') {
+          equal(map1, map2);
+        } else {
+          for (var key in map1) {
+            checkRecursively(map1[key], map2[key]);
+          }
+        }
+      }
+    }
+
+    test("Void", function() {
+      equal(client.testVoid(), undefined);
+    });
+    test("Binary (String)", function() {
+      var binary = '';
+      for (var v = 255; v >= 0; --v) {
+        binary += String.fromCharCode(v);
+      }
+      equal(client.testBinary(binary), binary);
+    });
+    test("Binary (Uint8Array)", function() {
+      var binary = '';
+      for (var v = 255; v >= 0; --v) {
+        binary += String.fromCharCode(v);
+      }
+      var arr = new Uint8Array(binary.length);
+      for (var i = 0; i < binary.length; ++i) {
+        arr[i] = binary[i].charCodeAt();
+      }
+      equal(client.testBinary(arr), binary);
+    });
+    test("String", function() {
+      equal(client.testString(''), '');
+      equal(client.testString(stringTest), stringTest);
+
+      var specialCharacters = 'quote: \" backslash:' +
+        ' forwardslash-escaped: \/ ' +
+          ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
+            ' now-all-of-them-together: "\\\/\b\n\r\t' +
+              ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
+              equal(client.testString(specialCharacters),specialCharacters);
+    });
+    test("Double", function() {
+      equal(client.testDouble(0), 0);
+      equal(client.testDouble(-1), -1);
+      equal(client.testDouble(3.14), 3.14);
+      equal(client.testDouble(Math.pow(2,60)), Math.pow(2,60));
+    });
+    test("Bool", function() {
+      equal(client.testBool(true), true);
+      equal(client.testBool(false), false);
+    });
+    test("I8", function() {
+      equal(client.testByte(0), 0);
+      equal(client.testByte(0x01), 0x01);
+    });
+    test("I32", function() {
+      equal(client.testI32(0), 0);
+      equal(client.testI32(Math.pow(2,30)), Math.pow(2,30));
+      equal(client.testI32(-Math.pow(2,30)), -Math.pow(2,30));
+    });
+    test("I64", function() {
+      equal(client.testI64(0), 0);
+      //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+      equal(client.testI64(Math.pow(2,52)), Math.pow(2,52));
+      equal(client.testI64(-Math.pow(2,52)), -Math.pow(2,52));
+    });
+
+    test("Struct", function() {
+      var structTestInput = new ThriftTest.Xtruct();
+      structTestInput.string_thing = 'worked';
+      structTestInput.byte_thing = 0x01;
+      structTestInput.i32_thing = Math.pow(2,30);
+      //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+      structTestInput.i64_thing = Math.pow(2,52);
+
+      var structTestOutput = client.testStruct(structTestInput);
+
+      equal(structTestOutput.string_thing, structTestInput.string_thing);
+      equal(structTestOutput.byte_thing, structTestInput.byte_thing);
+      equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+      equal(structTestOutput.i64_thing, structTestInput.i64_thing);
+
+      equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
+    });
+
+    test("Nest", function() {
+      var xtrTestInput = new ThriftTest.Xtruct();
+      xtrTestInput.string_thing = 'worked';
+      xtrTestInput.byte_thing = 0x01;
+      xtrTestInput.i32_thing = Math.pow(2,30);
+      //This is usually 2^60 but JS cannot represent anything over 2^52 accurately
+      xtrTestInput.i64_thing = Math.pow(2,52);
+
+      var nestTestInput = new ThriftTest.Xtruct2();
+      nestTestInput.byte_thing = 0x02;
+      nestTestInput.struct_thing = xtrTestInput;
+      nestTestInput.i32_thing = Math.pow(2,15);
+
+      var nestTestOutput = client.testNest(nestTestInput);
+
+      equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);
+      equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+      equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+      equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+      equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+      equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);
+
+      equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
+    });
+
+    test("Map", function() {
+      var mapTestInput = {7:77, 8:88, 9:99};
+
+      var mapTestOutput = client.testMap(mapTestInput);
+
+      for (var key in mapTestOutput) {
+        equal(mapTestOutput[key], mapTestInput[key]);
+      }
+    });
+
+    test("StringMap", function() {
+      var mapTestInput = {
+        "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
+        "longValue":stringTest, stringTest:"long key"
+      };
+
+      var mapTestOutput = client.testStringMap(mapTestInput);
+
+      for (var key in mapTestOutput) {
+        equal(mapTestOutput[key], mapTestInput[key]);
+      }
+    });
+
+    test("Set", function() {
+      var setTestInput = [1,2,3];
+      ok(client.testSet(setTestInput), setTestInput);
+    });
+
+    test("List", function() {
+      var listTestInput = [1,2,3];
+      ok(client.testList(listTestInput), listTestInput);
+    });
+
+    test("Enum", function() {
+      equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
+    });
+
+    test("TypeDef", function() {
+      equal(client.testTypedef(69), 69);
+    });
+
+    test("Skip", function() {
+      var structTestInput = new ThriftTest.Xtruct();
+      var modifiedClient = new ThriftTest.ThriftTestClient(protocol);
+
+      modifiedClient.recv_testStruct = function() {
+        var input  = modifiedClient.input;
+        var xtruct3 = new ThriftTest.Xtruct3();
+
+        input.readMessageBegin();
+        input.readStructBegin();
+
+        // read Xtruct data with Xtruct3
+        input.readFieldBegin();
+        xtruct3.read(input);
+        input.readFieldEnd();
+        // read Thrift.Type.STOP message
+        input.readFieldBegin();
+        input.readFieldEnd();
+
+        input.readStructEnd();
+        input.readMessageEnd();
+
+        return xtruct3;
+      };
+
+      structTestInput.string_thing = 'worked';
+      structTestInput.byte_thing   = 0x01;
+      structTestInput.i32_thing    = Math.pow(2,30);
+      structTestInput.i64_thing    = Math.pow(2,52);
+
+      var structTestOutput = modifiedClient.testStruct(structTestInput);
+
+      equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
+      equal(structTestOutput.string_thing, structTestInput.string_thing);
+      equal(structTestOutput.changed, null);
+      equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+      equal(structTestOutput.i64_thing, structTestInput.i64_thing);
+    });
+
+    test("MapMap", function() {
+      var mapMapTestExpectedResult = {
+        "4":{"1":1,"2":2,"3":3,"4":4},
+        "-4":{"-4":-4, "-3":-3, "-2":-2, "-1":-1}
+      };
+
+      var mapMapTestOutput = client.testMapMap(1);
+
+
+      for (var key in mapMapTestOutput) {
+        for (var key2 in mapMapTestOutput[key]) {
+          equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
+        }
+      }
+
+      checkRecursively(mapMapTestOutput, mapMapTestExpectedResult);
+    });
+
+    test("Xception", function() {
+      try {
+        client.testException("Xception");
+        ok(false);
+      } catch (e) {
+        equal(e.errorCode, 1001);
+        equal(e.message, "Xception");
+      }
+    });
+
+    test("no Exception", function() {
+      try {
+        client.testException("no Exception");
+      } catch (e) {
+        ok(false);
+      }
+    });
+
+    test("TException", function() {
+      try {
+        client.testException("TException");
+        ok(false);
+      } catch(e) {
+        ok(ok);
+      }
+    });
+
+    var crazy = {
+      "userMap":{ "5":5, "8":8 },
+      "xtructs":[{
+        "string_thing":"Goodbye4",
+        "byte_thing":4,
+        "i32_thing":4,
+        "i64_thing":4
+      },
+      {
+        "string_thing":"Hello2",
+        "byte_thing":2,
+        "i32_thing":2,
+        "i64_thing":2
+      }]
+    };
+    test("Insanity", function() {
+      var insanity = {
+        "1":{
+          "2":crazy,
+          "3":crazy
+        },
+        "2":{ "6":{ "userMap":null, "xtructs":null } }
+      };
+      var res = client.testInsanity(new ThriftTest.Insanity(crazy));
+      ok(res, JSON.stringify(res));
+      ok(insanity, JSON.stringify(insanity));
+
+      checkRecursively(res, insanity);
+    });
+
+    console.log('------------------------------------------------------------');
+    console.log('### All tests succeeded.');
+    return 0;
+  };
+
+  try {
+    var ret = execute();
+    phantom.exit(ret);
+  } catch (err) {
+    // Catch all and exit to avoid hang.
+    console.error(err);
+    phantom.exit(1);
+  }
+})();

http://git-wip-us.apache.org/repos/asf/thrift/blob/6defea5f/lib/js/test/test.js
----------------------------------------------------------------------
diff --git a/lib/js/test/test.js b/lib/js/test/test.js
index 0c7d2cb..2d8ec9b 100755
--- a/lib/js/test/test.js
+++ b/lib/js/test/test.js
@@ -58,7 +58,7 @@ if (typeof QUnit.log == 'function') {
     if (!details.result) {
       console.log('======== FAIL ========');
       console.log('TestName: ' + details.name);
-      details.message && console.log(details.message);
+      if (details.message) console.log(details.message);
       console.log('Expected: ' + details.expected);
       console.log('Actual  : ' + details.actual);
       console.log('======================');
@@ -86,6 +86,24 @@ module("Base Types");
   test("Void", function() {
     equal(client.testVoid(), undefined);
   });
+  test("Binary (String)", function() {
+    var binary = '';
+    for (var v = 255; v >= 0; --v) {
+      binary += String.fromCharCode(v);
+    }
+    equal(client.testBinary(binary), binary);
+  });
+  test("Binary (Uint8Array)", function() {
+    var binary = '';
+    for (var v = 255; v >= 0; --v) {
+      binary += String.fromCharCode(v);
+    }
+    var arr = new Uint8Array(binary.length);
+    for (var i = 0; i < binary.length; ++i) {
+      arr[i] = binary[i].charCodeAt();
+    }
+    equal(client.testBinary(arr), binary);
+  });
   test("String", function() {
     equal(client.testString(''), '');
     equal(client.testString(stringTest), stringTest);

http://git-wip-us.apache.org/repos/asf/thrift/blob/6defea5f/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index afc7531..2c1aa70 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -466,5 +466,24 @@
       ]
     },
     "workdir": "erl"
+  },
+  {
+    "name": "js",
+    "transports": [
+      "http"
+    ],
+    "sockets": [
+      "ip"
+    ],
+    "protocols": [
+      "json"
+    ],
+    "client": {
+      "command": [
+        "phantomjs",
+        "test/phantom-client.js"
+      ]
+    },
+    "workdir": "../lib/js"
   }
 ]


[2/5] thrift git commit: THRIFT-3350 Python JSON protocol does not encode binary as Base64 Client: Python Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3350 Python JSON protocol does not encode binary as Base64
Client: Python
Patch: Nobuaki Sukegawa

This closes #697


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/bc7e480d
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/bc7e480d
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/bc7e480d

Branch: refs/heads/master
Commit: bc7e480d0fc80501b597ed57b94395e1c85a2069
Parents: 97a4898
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sat Nov 14 19:23:27 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Nov 15 14:00:18 2015 +0900

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_py_generator.cc | 14 ++++++---
 lib/py/src/protocol/TJSONProtocol.py        |  6 ++++
 lib/py/src/protocol/TProtocol.py            | 40 ++++++++++++++++--------
 test/known_failures_Linux.json              |  4 ---
 test/py/TestClient.py                       |  2 --
 5 files changed, 43 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/bc7e480d/compiler/cpp/src/generate/t_py_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 74904ac..31936b7 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -1944,7 +1944,9 @@ void t_py_generator::generate_deserialize_field(ofstream& out,
         throw "compiler error: cannot serialize void field in a struct: " + name;
         break;
       case t_base_type::TYPE_STRING:
-        if (((t_base_type*)type)->is_binary() || !gen_utf8strings_) {
+        if (((t_base_type*)type)->is_binary()) {
+          out << "readBinary()";
+        } else if(!gen_utf8strings_) {
           out << "readString()";
         } else {
           out << "readString().decode('utf-8')";
@@ -2117,7 +2119,9 @@ void t_py_generator::generate_serialize_field(ofstream& out, t_field* tfield, st
         throw "compiler error: cannot serialize void field in a struct: " + name;
         break;
       case t_base_type::TYPE_STRING:
-        if (((t_base_type*)type)->is_binary() || !gen_utf8strings_) {
+        if (((t_base_type*)type)->is_binary()) {
+          out << "writeBinary(" << name << ")";
+        } else if (!gen_utf8strings_) {
           out << "writeString(" << name << ")";
         } else {
           out << "writeString(" << name << ".encode('utf-8'))";
@@ -2455,8 +2459,10 @@ string t_py_generator::type_to_spec_args(t_type* ttype) {
     ttype = ((t_typedef*)ttype)->get_type();
   }
 
-  if (ttype->is_base_type() || ttype->is_enum()) {
-    return "None";
+  if (ttype->is_base_type() && reinterpret_cast<t_base_type*>(ttype)->is_binary()) {
+    return  "'BINARY'";
+  } else if (ttype->is_base_type() || ttype->is_enum()) {
+    return  "None";
   } else if (ttype->is_struct() || ttype->is_xception()) {
     return "(" + type_name(ttype) + ", " + type_name(ttype) + ".thrift_spec)";
   } else if (ttype->is_map()) {

http://git-wip-us.apache.org/repos/asf/thrift/blob/bc7e480d/lib/py/src/protocol/TJSONProtocol.py
----------------------------------------------------------------------
diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py
index aada3fc..7d56545 100644
--- a/lib/py/src/protocol/TJSONProtocol.py
+++ b/lib/py/src/protocol/TJSONProtocol.py
@@ -362,6 +362,12 @@ class TJSONProtocolBase(TProtocolBase):
 
   def readJSONBase64(self):
     string = self.readJSONString(False)
+    size = len(string)
+    m = size % 4
+    # Force padding since b64encode method does not allow it
+    if m != 0:
+      for i in range(4 - m):
+        string += '='
     return base64.b64decode(string)
 
   def readJSONObjectStart(self):

http://git-wip-us.apache.org/repos/asf/thrift/blob/bc7e480d/lib/py/src/protocol/TProtocol.py
----------------------------------------------------------------------
diff --git a/lib/py/src/protocol/TProtocol.py b/lib/py/src/protocol/TProtocol.py
index 22339c0..ca22c48 100644
--- a/lib/py/src/protocol/TProtocol.py
+++ b/lib/py/src/protocol/TProtocol.py
@@ -108,6 +108,9 @@ class TProtocolBase:
   def writeBinary(self, str_val):
     pass
 
+  def writeBinary(self, str_val):
+    return self.writeString(str_val)
+
   def readMessageBegin(self):
     pass
 
@@ -168,6 +171,9 @@ class TProtocolBase:
   def readBinary(self):
     pass
 
+  def readBinary(self):
+    return self.readString()
+
   def skip(self, ttype):
     if ttype == TType.STOP:
       return
@@ -216,7 +222,7 @@ class TProtocolBase:
        (None, None, False),  # 0 TType.STOP
        (None, None, False),  # 1 TType.VOID # TODO: handle void?
        ('readBool', 'writeBool', False),  # 2 TType.BOOL
-       ('readByte',  'writeByte', False),  # 3 TType.BYTE and I08
+       ('readByte', 'writeByte', False),  # 3 TType.BYTE and I08
        ('readDouble', 'writeDouble', False),  # 4 TType.DOUBLE
        (None, None, False),  # 5 undefined
        ('readI16', 'writeI16', False),  # 6 TType.I16
@@ -233,9 +239,17 @@ class TProtocolBase:
        (None, None, False)  # 17 TType.UTF16 # TODO: handle utf16 types?
       )
 
+  def _ttype_handlers(self, ttype, spec):
+    if spec == 'BINARY':
+      if ttype != TType.STRING:
+        raise TProtocolException(type=TProtocolException.INVALID_DATA,
+                                 message='Invalid binary field type %d' % ttype)
+      return ('readBinary', 'writeBinary', False)
+    return self._TTYPE_HANDLERS[ttype]
+
   def readFieldByTType(self, ttype, spec):
     try:
-      (r_handler, w_handler, is_container) = self._TTYPE_HANDLERS[ttype]
+      (r_handler, w_handler, is_container) = self._ttype_handlers(ttype, spec)
     except IndexError:
       raise TProtocolException(type=TProtocolException.INVALID_DATA,
                                message='Invalid field type %d' % (ttype))
@@ -250,7 +264,7 @@ class TProtocolBase:
   def readContainerList(self, spec):
     results = []
     ttype, tspec = spec[0], spec[1]
-    r_handler = self._TTYPE_HANDLERS[ttype][0]
+    r_handler = self._ttype_handlers(ttype, spec)[0]
     reader = getattr(self, r_handler)
     (list_type, list_len) = self.readListBegin()
     if tspec is None:
@@ -259,7 +273,7 @@ class TProtocolBase:
         results.append(reader())
     else:
       # this is like an inlined readFieldByTType
-      container_reader = self._TTYPE_HANDLERS[list_type][0]
+      container_reader = self._ttype_handlers(list_type, tspec)[0]
       val_reader = getattr(self, container_reader)
       for idx in range(list_len):
         val = val_reader(tspec)
@@ -270,7 +284,7 @@ class TProtocolBase:
   def readContainerSet(self, spec):
     results = set()
     ttype, tspec = spec[0], spec[1]
-    r_handler = self._TTYPE_HANDLERS[ttype][0]
+    r_handler = self._ttype_handlers(ttype, spec)[0]
     reader = getattr(self, r_handler)
     (set_type, set_len) = self.readSetBegin()
     if tspec is None:
@@ -278,7 +292,7 @@ class TProtocolBase:
       for idx in range(set_len):
         results.add(reader())
     else:
-      container_reader = self._TTYPE_HANDLERS[set_type][0]
+      container_reader = self._ttype_handlers(set_type, tspec)[0]
       val_reader = getattr(self, container_reader)
       for idx in range(set_len):
         results.add(val_reader(tspec))
@@ -298,8 +312,8 @@ class TProtocolBase:
     (map_ktype, map_vtype, map_len) = self.readMapBegin()
     # TODO: compare types we just decoded with thrift_spec and
     # abort/skip if types disagree
-    key_reader = getattr(self, self._TTYPE_HANDLERS[key_ttype][0])
-    val_reader = getattr(self, self._TTYPE_HANDLERS[val_ttype][0])
+    key_reader = getattr(self, self._ttype_handlers(key_ttype, key_spec)[0])
+    val_reader = getattr(self, self._ttype_handlers(val_ttype, val_spec)[0])
     # list values are simple types
     for idx in range(map_len):
       if key_spec is None:
@@ -342,7 +356,7 @@ class TProtocolBase:
 
   def writeContainerList(self, val, spec):
     self.writeListBegin(spec[0], len(val))
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
+    r_handler, w_handler, is_container = self._ttype_handlers(spec[0], spec)
     e_writer = getattr(self, w_handler)
     if not is_container:
       for elem in val:
@@ -354,7 +368,7 @@ class TProtocolBase:
 
   def writeContainerSet(self, val, spec):
     self.writeSetBegin(spec[0], len(val))
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[spec[0]]
+    r_handler, w_handler, is_container = self._ttype_handlers(spec[0], spec)
     e_writer = getattr(self, w_handler)
     if not is_container:
       for elem in val:
@@ -367,8 +381,8 @@ class TProtocolBase:
   def writeContainerMap(self, val, spec):
     k_type = spec[0]
     v_type = spec[2]
-    ignore, ktype_name, k_is_container = self._TTYPE_HANDLERS[k_type]
-    ignore, vtype_name, v_is_container = self._TTYPE_HANDLERS[v_type]
+    ignore, ktype_name, k_is_container = self._ttype_handlers(k_type, spec)
+    ignore, vtype_name, v_is_container = self._ttype_handlers(v_type, spec)
     k_writer = getattr(self, ktype_name)
     v_writer = getattr(self, vtype_name)
     self.writeMapBegin(k_type, v_type, len(val))
@@ -404,7 +418,7 @@ class TProtocolBase:
     self.writeStructEnd()
 
   def writeFieldByTType(self, ttype, val, spec):
-    r_handler, w_handler, is_container = self._TTYPE_HANDLERS[ttype]
+    r_handler, w_handler, is_container = self._ttype_handlers(ttype, spec)
     writer = getattr(self, w_handler)
     if is_container:
       writer(val, spec)

http://git-wip-us.apache.org/repos/asf/thrift/blob/bc7e480d/test/known_failures_Linux.json
----------------------------------------------------------------------
diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json
index d326c59..b98e6c1 100644
--- a/test/known_failures_Linux.json
+++ b/test/known_failures_Linux.json
@@ -1,8 +1,4 @@
 [
-  "c_glib-py_binary-accel_buffered-ip",
-  "c_glib-py_binary-accel_framed-ip",
-  "c_glib-py_binary_buffered-ip",
-  "c_glib-py_binary_framed-ip",
   "c_glib-rb_binary-accel_buffered-ip",
   "c_glib-rb_binary-accel_framed-ip",
   "c_glib-rb_binary_buffered-ip",

http://git-wip-us.apache.org/repos/asf/thrift/blob/bc7e480d/test/py/TestClient.py
----------------------------------------------------------------------
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 5b858ef..051890b 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -126,8 +126,6 @@ class AbstractTest(unittest.TestCase):
     self.assertEqual(self.client.testDouble(-0.000341012439638598279), -0.000341012439638598279)
 
   def testBinary(self):
-    if isinstance(self, JSONTest):
-      self.skipTest('JSON protocol does not handle binary correctly.')
     print('testBinary')
     val = bytearray([i for i in range(0, 256)])
     self.assertEqual(bytearray(self.client.testBinary(bytes(val))), val)


[5/5] thrift git commit: THRIFT-3423 First call to thrift_transport:read_exact fails to dispatch correct function Client: Erlang Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3423 First call to thrift_transport:read_exact fails to dispatch correct function
Client: Erlang
Patch: Nobuaki Sukegawa

This closes #694


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/97a48988
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/97a48988
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/97a48988

Branch: refs/heads/master
Commit: 97a48988de6a7ac513311456a6f6d3ef7f587639
Parents: 7f404fd
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sat Nov 14 18:49:45 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Nov 15 14:00:18 2015 +0900

----------------------------------------------------------------------
 lib/erl/src/thrift_transport.erl | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/97a48988/lib/erl/src/thrift_transport.erl
----------------------------------------------------------------------
diff --git a/lib/erl/src/thrift_transport.erl b/lib/erl/src/thrift_transport.erl
index 31dac86..526050f 100644
--- a/lib/erl/src/thrift_transport.erl
+++ b/lib/erl/src/thrift_transport.erl
@@ -101,11 +101,14 @@ when is_integer(Len), Len >= 0 ->
 
 read_exact(Transport = #t_transport{module = Module}, Len)
 when is_integer(Len), Len >= 0 ->
-  case erlang:function_exported(Module, read_exact, 2) of
-      true ->
-        {NewState, Result} = Module:read_exact(Transport#t_transport.state, Len),
-        {Transport#t_transport{state = NewState}, Result};
-      false -> read(Transport, Len)
+  case lists:keyfind(read_exact, 1, Module:module_info(exports)) of
+    {read_exact, 2} ->
+      io:fwrite("HAS EXACT"),
+      {NewState, Result} = Module:read_exact(Transport#t_transport.state, Len),
+      {Transport#t_transport{state = NewState}, Result};
+    _ ->
+      io:fwrite("~p NO EXACT", [Module]),
+      read(Transport, Len)
   end.
 
 


[3/5] thrift git commit: Run test for THRIFT-2413

Posted by ns...@apache.org.
Run test for THRIFT-2413

Slightly simplify _toChar method too.

This closes #695


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/7f404fde
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/7f404fde
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/7f404fde

Branch: refs/heads/master
Commit: 7f404fdef23dbbe5204d35bcb9261ff50939f31f
Parents: f892674
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sat Nov 14 17:05:42 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Nov 15 14:00:18 2015 +0900

----------------------------------------------------------------------
 lib/py/Makefile.am                   | 10 ++++++----
 lib/py/src/protocol/TJSONProtocol.py | 14 +++++---------
 2 files changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/7f404fde/lib/py/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/py/Makefile.am b/lib/py/Makefile.am
index b88b6be..c0db871 100755
--- a/lib/py/Makefile.am
+++ b/lib/py/Makefile.am
@@ -22,13 +22,14 @@ DESTDIR ?= /
 if WITH_PY3
 py3-build:
 	$(PYTHON3) setup.py build
+py3-test: py3-build
+	PYTHONPATH=build/lib $(PYTHON3) test/thrift_json.py
 else
 py3-build:
+py3-test:
 endif
 
-testing:
-
-all-local: py3-build testing
+all-local: py3-build
 	$(PYTHON) setup.py build
 
 # We're ignoring prefix here because site-packages seems to be
@@ -41,7 +42,8 @@ install-exec-hook:
 clean-local:
 	$(RM) -r build
 
-check-local: all
+check-local: all py3-test
+	PYTHONPATH=$(shell ls build/lib* -dr | head -n1) $(PYTHON) test/thrift_json.py
 
 EXTRA_DIST = \
 	CMakeLists.txt \

http://git-wip-us.apache.org/repos/asf/thrift/blob/7f404fde/lib/py/src/protocol/TJSONProtocol.py
----------------------------------------------------------------------
diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py
index d210bff..aada3fc 100644
--- a/lib/py/src/protocol/TJSONProtocol.py
+++ b/lib/py/src/protocol/TJSONProtocol.py
@@ -251,18 +251,14 @@ class TJSONProtocolBase(TProtocolBase):
 
   def _toChar(self, high, low=None):
     if not low:
-      if sys.version_info[0] == 2:
-        return ("\\u%04x" % high).decode('unicode-escape').encode('utf-8')
-      else:
-        return chr(high)
+      codepoint = high
     else:
       codepoint = (1 << 16) + ((high & 0x3ff) << 10)
       codepoint += low & 0x3ff
-      if sys.version_info[0] == 2:
-        s = "\\U%08x" % codepoint
-        return s.decode('unicode-escape').encode('utf-8')
-      else:
-        return chr(codepoint)
+    if sys.version_info[0] == 2:
+      return unichr(codepoint).encode('utf-8')
+    else:
+      return chr(codepoint)
 
   def readJSONString(self, skipContext):
     highSurrogate = None